Pagini recente » Cod sursa (job #873487) | Cod sursa (job #785966) | Cod sursa (job #1520757)
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX_LEN = 1000000;
char s[2 + MAX_LEN];
int pi[1 + MAX_LEN];
int main() {
freopen("prefix.in", "r", stdin);
freopen("prefix.out", "w", stdout);
int t, i, n, q;
scanf("%d\n", &t);
while(t--) {
gets(s + 1);
n = strlen(s + 1);
for(i = 2, pi[1] = 0, q = 0; i <= n; i++) {
while(q > 0 && s[q + 1] != s[i]) q = pi[q];
if(s[q + 1] == s[i]) q++;
pi[i] = q;
}
for(i = n; i && (pi[i] == 0 || (i % (i - pi[i])) != 0); i--);
printf("%d\n", i);
}
return 0;
}