Pagini recente » Cod sursa (job #2661719) | Cod sursa (job #2797965) | Cod sursa (job #251648) | Cod sursa (job #1322871) | Cod sursa (job #341149)
Cod sursa(job #341149)
var s:array[1..1000000] of char;
pi:array[1..1000000] of longint;
t,contor,k,i,m,a:longint;
f,g:text;
begin
assign(f,'prefix.in');
assign(g,'prefix.out');
reset(f);rewrite(g);
readln(f,t);
for contor:=1 to t do
begin
m:=0;
while not seekeoln(f) do
begin
m:=m+1;
read(f,s[m]);
end;
readln(f);
pi[1]:=0;
k:=0;a:=0;
for i:=2 to m do
begin
while (k>0) and (s[k+1]<>s[i]) do
k:=pi[k];
if s[k+1]=s[i] then
k:=k+1;
pi[i]:=k;
if (k>0) and (i mod (i-k)=0) then
a:=i;
end;
writeln(g,a);
end;
close(f);close(g);
end.