Pagini recente » Cod sursa (job #2258593) | Cod sursa (job #1898786) | Cod sursa (job #2840742) | Cod sursa (job #2444391) | Cod sursa (job #2467576)
#include <bits/stdc++.h>
using namespace std;
ifstream in("strmatch.in");
ofstream out("strmatch.out");
const int N = 1e6+5;
int pi[N], n;
char a[N];
void PiTable()
{
int q = 0;
pi[1] = 0;
for (int i = 2; i<=n; i++)
{
while (a[i]!=a[q+1] && q>0)
q = pi[q];
if (a[i] == a[q+1])
q++;
pi[i] = q;
}
}
int main()
{
int t;
in >> t;
while (t--)
{
in >> (a+1);
n = strlen(a+1);
memset(pi,0,sizeof(pi));
PiTable();
int Max = 0;
for (int i = 2; i<=n; i++)
if (pi[i] && i%(i-pi[i]) == 0)
Max = max(Max,i);
out << Max << "\n";
}
}