Pagini recente » Cod sursa (job #364254) | Cod sursa (job #1975447) | Cod sursa (job #2654230) | Cod sursa (job #2859763) | Cod sursa (job #78781)
Cod sursa(job #78781)
program prefix;
const
fin='prefix.in';
fout='prefix.out';
type
sir=array[1..1000010] of char;
psir=^sir;
lsir=array[0..1000010] of longint;
plsir=^lsir;
var
t,i,j,n,k,q,l,x,y,it,best:longint;
p:psir;
pi:plsir;
begin
assign(input,fin);assign(output,fout);
reset(input);rewrite(output);
readln(t);
new(p);new(pi);
for it:=1 to t do
begin
l:=0;
while not(seekeoln(input)) do
begin
inc(l);
read(p^[l]);
end;
readln;
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:=i-pi^[i];
if (x<>0)and(i<>x) then
if (i=(i div x)*x) then
best:=i;
end;
writeln(best);
end;
close(input);close(output);
end.