Pagini recente » Cod sursa (job #1108833) | Cod sursa (job #423034) | Cod sursa (job #143032) | Cod sursa (job #2893859) | Cod sursa (job #329372)
Cod sursa(job #329372)
#include <stdio.h>
#include <string.h>
#define max 1000002
char P[max];
int n, pi[max], t,q, k,rez;
int main()
{
freopen("prefix.in", "r", stdin);
freopen("prefix.out", "w", stdout);
scanf("%d\n", &t);
for (; t; t--)
{
scanf("%s\n", P+1);
n=strlen(P+1);
pi[1]=0;k=0;
for (q=2; q<=n; q++)
{
while (k && P[k+1]!=P[q]) k=pi[k];
if (P[k+1]==P[q]) k++;
pi[q]=k;
if (k && (q%(q-k))==0) rez=q;
}
printf("%d\n",rez);
}
return 0;
}