Pagini recente » Simulare 27 | Cod sursa (job #551732) | Cod sursa (job #1915153) | Cod sursa (job #438788) | Cod sursa (job #177859)
Cod sursa(job #177859)
var s:ansistring;
pi:array[0..1000001] of longint;
n,i,j,t,q,x,max:longint;
begin
assign(input,'prefix.in');reset(input);
assign(output,'prefix.out');rewrite(output);
readln(t);
for q:=1 to t do
begin
fillchar(pi,sizeof(pi),0);
readln(s);
n:=length(s);
pi[0]:=-1;
pi[1]:=0;
for i:=2 to n do
begin
x:=pi[i-1];
if s[i]=s[x+1] then
pi[i]:=x+1
else
begin
while x>=0 do
begin
x:=pi[x];
if x<0 then
break;
if s[i]=s[x+1] then
begin
pi[i]:=x+1;
break;
end;
end;
end;
end;
max:=0;
for i:=1 to n do
if (i div (i-pi[i])>=2)and(i mod (i-pi[i])=0) then
max:=i;
writeln(max);
end;
close(input);close(output);
end.