Pagini recente » Cod sursa (job #1959531) | Cod sursa (job #907726) | Cod sursa (job #44362) | Cod sursa (job #964566) | Cod sursa (job #1640220)
// Template v2
#define pb push_back
#define mp make_pair
#define first x
#define second y
#define l(x) x<<1
#define r(x) x<<1 | 1
#define P 73
#define MOD1 3000017
#define MOD2 3000541
#include<fstream>
using namespace std;
ifstream cin("prefix.in");
ofstream cout("prefix.out");
typedef long long LL;
typedef long double LD;
// primes less than 100
const int PRIM[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
const int CMAX = 10005;
const int MOD = 1000000007;
const int NMAX = 1000005;
const short INF16 = 32000;
const int INF = int(1e9);
const LL INF64 = LL(1e18);
char A[NMAX];
int n, pi[NMAX];
int t,rs,q;
void prefix()
{
q=0;
pi[1]=0;
for(int i=2; A[i]; ++i)
{
while(q && A[q+1] != A[i])
q=pi[q];
if(A[q+1] == A[i])
q++;
pi[i]=q;
if(pi[i]%(i-pi[i])==0 && pi[i]!=0)
rs=i;
}
}
void read()
{
(cin>>t).ignore(1);
while(t--){
rs=0;
cin.getline(A+1, NMAX+2);
prefix();
cout<<rs<<"\n";
}
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
read();
return 0;
}