Pagini recente » Cod sursa (job #1341790) | Cod sursa (job #403261) | Cod sursa (job #1411019) | Cod sursa (job #1476424) | Cod sursa (job #78780)
Cod sursa(job #78780)
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:=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.