题目链接:http://poj.org/problem?id=2406

题意:找最小循环节的循环次数

解法:KMP

//POJ 2406

#include <stdio.h>
#include <string.h>
const int maxn = 4000010;
char s[maxn];
int fail[maxn];

int main()
{
    while(scanf("%s", s+1) != EOF){
        if(s[1] == '.') break;
        memset(fail, 0, sizeof(fail));
        int j = 0;
        int len = strlen(s+1);
        for(int i = 2; i <= len; i++){
            while(j > 0 && s[j+1] != s[i]) j = fail[j];
            if(s[j+1] == s[i]) j++;
            fail[i] = j;
        }
        if(len%(len-fail[len])) puts("1");
        else printf("%d\n", len/(len-fail[len]));
    }
    return 0;
}