Pagini recente » Cod sursa (job #392017) | Cod sursa (job #676663) | Cod sursa (job #3198952) | Cod sursa (job #136042) | Cod sursa (job #78765)
Cod sursa(job #78765)
program prefix;
const
fin='prefix.in';
fout='prefix.out';
var
t,i,j,n,k,q,l,x,y,it,best:longint;
p:array[1..1000000] of char;
pi:array[0..1000000] of longint;
begin
assign(input,fin);assign(output,fout);
reset(input);rewrite(output);
readln(t);
for it:=1 to t do
begin
l:=0;
fillchar(p,sizeof(p),' ');
readln(p);
repeat
inc(l);
until p[l]=' ';
dec(l);
k:=0;
pi[1]:=0;
for q:=2 to l do
begin
while (k>0) and (p[k+1]<>p[q]) do
k:=pi[k];
if p[k+1]=p[q] then
inc(k);
pi[q]:=k;
end;
best:=0;
for i:=2 to l do
begin
x:=pi[i]-pi[pi[i]];
if x<>0 then
if (i mod x=0) and (i<>x) then
if i-pi[i]=x then
if best<i then
best:=i;
end;
writeln(best);
end;
close(input);close(output);
end.