Pagini recente » Clasament FMI No Stress 4 | Cod sursa (job #65191) | Cod sursa (job #1109644) | Cod sursa (job #563162) | Cod sursa (job #2089860)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("prefix.in");
ofstream fout("prefix.out");
const int CMAX = 1000000 + 5;
int teste, len;
int phi[CMAX];
char text[CMAX];
void prefix()
{
memset(phi, 0, sizeof(phi));
for (int i = 2; i <= len; ++i)
{
int last = phi[i - 1];
while (last > 0 && text[i] != text[last + 1]) last = phi[last];
if (text[i] == text[last + 1]) phi[i] = last + 1;
}
}
int main()
{
fin >> teste;
while (teste--)
{
int maxx = 0;
fin >> (text + 1);
len = strlen(text + 1);
prefix();
for (int i = 1; i <= len; ++i)
if (i % (i - phi[i]) == 0 && phi[i])
maxx = max(maxx, i);
fout << maxx << '\n';
}
return 0;
}