Pagini recente » Borderou de evaluare (job #3314171) | Cod sursa (job #3329037)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("prefix.in");
ofstream fout("prefix.out");
const int lim = 1e6 + 5;
int t, n, lps[lim], ans;
char a[lim];
void precalc()
{
int k = 0;
for (int i = 2; i <= n; ++i)
{
while (k && a[k] != a[i - 1]) k = lps[k];
if (a[k] == a[i - 1]) k++;
lps[i] = k;
if (lps[i] > 0 && i % (i - lps[i]) == 0) ans = i;
}
for (int i = 0; i <= n ; ++i) lps[i] = 0;
}
void testcase()
{
fin >> a;
n = strlen(a);
precalc();
fout << ans <<'\n';
}
int main()
{
fin >> t;
for (; t; --t)
testcase();
return 0;
}