Pagini recente » Cod sursa (job #1471083) | Arhiva de probleme | Cod sursa (job #1963899) | Cod sursa (job #1053491) | Cod sursa (job #2561485)
/*
`-/oo+/- ``
.oyhhhhhhyo.`od
+hhhhyyoooos. h/
+hhyso++oosy- /s
.yoooossyyo:``-y`
..----.` ``.-/+:.`
`````..-::/.
`..```.-::///`
`-.....--::::/:
`.......--::////:
`...`....---:::://:
`......``..--:::::///:`
`---.......--:::::////+/`
----------::::::/::///++:
----:---:::::///////////:`
.----::::::////////////:-`
`----::::::::::/::::::::-
`.-----:::::::::::::::-
...----:::::::::/:-`
`.---::/+osss+:`
``.:://///-.
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;
const int INF = 2e9;
const int N = 1e6;
char v[5 + N];
int pi[5 + N];
int main() {
freopen("prefix.in", "r", stdin);
freopen("prefix.out", "w", stdout);
int t, n;
scanf("%d\n", &t);
while(t--){
int ans(0);
fgets(v, 3 + N, stdin);
n = strlen(v) - 1;
for(int i = 1; i <= n; i++){
int j;
j = pi[i - 1];
while(j > 0 && v[i] != v[j])
j = pi[j - 1];
if(v[i] == v[j]) j++;
pi[i] = j;
if(pi[i - 1] > 0 && i % (i - pi[i - 1]) == 0)
ans = max(ans, i);
}
printf("%d\n", ans);
}
return 0;
}