Pagini recente » Cod sursa (job #1656433) | Cod sursa (job #2207338) | Cod sursa (job #979647) | Cod sursa (job #2189842) | Cod sursa (job #78782)
Cod sursa(job #78782)
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;
f:text;
p:psir;
pi:plsir;
begin
assign(f,fin);assign(output,fout);
reset(f);rewrite(output);
readln(f,t);
new(p);new(pi);
for it:=1 to t do
begin
l:=0;
readln(f,p^);
repeat
inc(l);
until (p^[l]<'a')or(p^[l]>'z');
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:=i-pi^[i];
if (x<>0)and(i<>x) then
if (i=(i div x)*x) then
best:=i;
end;
writeln(best);
end;
close(f);close(output);
end.