Pagini recente » Cod sursa (job #2471577) | Cod sursa (job #2285629) | Cod sursa (job #348752) | Cod sursa (job #1359190) | Cod sursa (job #78779)
Cod sursa(job #78779)
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
readln(p^);
k:=0;
pi^[1]:=0;
q:=2;
repeat
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;
inc(q);
until (p^[q]<'a')or(p^[q]>'z');
l:=q-1;
best:=0;
for i:=2 to l do
begin
x:=pi^[i]-pi^[pi^[i]];
if x<>0 then
if (((i=(i div x)*x) and (i<>x))and(i-pi^[i]=x))and(best<i) then
best:=i;
end;
writeln(best);
end;
close(input);close(output);
end.