Cod sursa(job #3329047)

Utilizator BiceaToader David Stefan Bicea Data 11 decembrie 2025 16:44:25
Problema Reguli Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("reguli.in");
ofstream fout("reguli.out");
const int lim = 500001;
int n, m, lps[lim], v[1005], t,w;
char a[lim],b[lim];
void precalc()
{
    int k = 0;
    for (int i = 2; i <=t ; ++i)
    {
        while (k && a[k] != a[i - 1]) k = lps[k];
        if (a[k] == a[i - 1]) k++;
        lps[i] = k;
        //if(lps[i])
        //if(!(i%(i-lps[i])))
    }
}
int main()
{fin>>t;
for(int i=1;i<=t;++i)
   {fin >> a;
   for(int j=0;j<=t-1;j++)
    b[j]=a[j+1]-a[j];
    w=0;
    precalc();
    w=t-lps[t];
    while(w)
    {
      if(lps[w] && !(w%(w-lps[w])))
         {fout<<w;
           w=0;
         }
    }
   }
    return 0;
}