Pagini recente » Cod sursa (job #222322) | Cod sursa (job #1683522) | Cod sursa (job #1694291) | Cod sursa (job #930437) | Cod sursa (job #19519)
Cod sursa(job #19519)
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;
for m:=1 to n do
if (pi[m]>0) and (m mod (m-pi[m])=0) and (m>sol) then sol:=m;
if sol>1
then writeln(sol)
else writeln('0');
dec(test);
end;
close(output);
close(input);
end.