求最小循环节
#include <cstdio>
#include <cstring>
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int const MAXN = 200010;
char s[MAXN];
int next[MAXN],dp[MAXN];
inline void Get_Next(int n){
memset(next,0,sizeof(next));
for(int i = 1;i < n;i++){
int j = next[i];
while(j && s[i] != s[j]) j = next[j];
if(s[i] == s[j]) next[i + 1] = j + 1;
else next[i + 1] = 0;
}
}
int main(){
int T;
while(~scanf("%d",&T)){
while(T--){
scanf("%s",s);
int n = strlen(s);
Get_Next(n);
int l = n - next[n];
if(l == n) printf("%d\n",n);
else if(n % l == 0) printf("0\n");
else printf("%d\n", l - n % l);
}
}
return 0;
}