Pagini recente » Cod sursa (job #1468648) | Cod sursa (job #1806775) | Cod sursa (job #979655) | Cod sursa (job #386077) | Cod sursa (job #1725169)
#include <fstream>
using namespace std;
char str[2000000];
int PI[2000000];
int main() {
ifstream fin("prefix.in");
ofstream fout("prefix.out");
int t;
fin >> t;
while(t--) {
fin >> (str + 1);
PI[0] = -1;
int ans = 0;
for(int i = 1; str[i]; ++i) {
int j = PI[i - 1];
while(j != -1 && str[j + 1] != str[i])
j = PI[j];
PI[i] = j + 1;
if(2 * PI[i] < i) continue;
if(i % (i - PI[i]) == 0)
ans = i;
}
fout << ans << '\n';
}
return 0;
}