Pagini recente » Cod sursa (job #1504839) | Cod sursa (job #2097058) | Cod sursa (job #757269) | Cod sursa (job #36952) | Cod sursa (job #19800)
Cod sursa(job #19800)
const
lim=1000100;
var
pi:array[1..lim] of longint;
t:array[1..lim] of char;
m,k,test,q,i,j,n,sol:longint;
procedure prefix;
begin
k:=0;
for q:=2 to n do
begin
while (k>0) and (t[k+1]<>t[q]) do k:=pi[k];
if t[k+1]=t[q] then inc(k);
pi[q]:=k;
end;
end;
begin
assign(input,'prefix.in');
reset(input);
assign(output,'prefix.out');
rewrite(output);
readln(test);
while test>0 do
begin
n:=0;
while not seekeoln do
begin
inc(n);
read(t[n]);
end;
readln;
prefix;
sol:=0;
m:=n;
while (m>0) and (sol=0) do
begin
if (pi[m]>0) and (m mod (m-pi[m])=0) then sol:=m;
dec(m);
end;
if sol>1
then writeln(sol)
else writeln('0');
dec(test);
end;
close(output);
close(input);
end.