Pagini recente » Cod sursa (job #1434709) | Cod sursa (job #1752853) | Cod sursa (job #144995) | Cod sursa (job #2978320) | Cod sursa (job #3144774)
#include<bits/stdc++.h>
//#define inf 0x3f3f3f3f
#define int long long
#define bit(x,i)(((x)>>(i))&1)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ifstream fin("prefix.in");
ofstream fout("prefix.out");
const int mod=1e9+7;
//typedef long long ll;
//const long long int mare=1LL*1000000000000000000;
const int mare=2e9+5;
const int nmax=1e6+5;
int T,n,m,i,j,t,suma,poz,ok,contor;
int x,y,c,st,dr,mij;
string a;
int pi[nmax];
signed main() {
FAST
fin >> T;
while (T--)
{
fin >> a;
n = a.size() + 1;
a = '#' + a;
contor=0;
t=0;
for (i = 2; i < n; i++) {
pi[i]=0;
while (t && a[t + 1] != a[i])
t = pi[t];
if (a[t + 1] == a[i])
t++;
pi[i] = t;
suma=i-pi[i];
if(pi[i])
if(i%suma==0)
contor=i;
}
fout<<contor<<"\n";
}
return 0;
}