Pagini recente » Cod sursa (job #2707773) | Cod sursa (job #2539787) | Cod sursa (job #3177810) | Cod sursa (job #514342) | Cod sursa (job #78775)
Cod sursa(job #78775)
program prefix;
const
fin='prefix.in';
fout='prefix.out';
var
t,i,j,n,k,q,l,x,y,it,best:longint;
p:array[1..1000010] of char;
pi:array[0..1000010] of longint;
begin
assign(input,fin);assign(output,fout);
reset(input);rewrite(output);
readln(t);
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) then
if i-pi[i]=x then
if best<i then
best:=i;
end;
writeln(best);
end;
close(input);close(output);
end.