题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358
题意 :求给你个串,前i位子串由某个字符串重复k次得到,求所有的i和k(k>1);
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> using namespace std; const int N = 1e6+7; char s[N]; int Next[N], n; void GetNext() { int i=0, j=-1; Next[0] = -1; while(i<n) { if(j==-1 || s[i] == s[j]) Next[++i] = ++j; else j=Next[j]; } } int main() { int t=1; while(scanf("%d", &n),n) { scanf("%s", s); GetNext(); printf("Test case #%d\n", t++); for(int i=2; i<=n; i++) { int Min_cycle = i - Next[i]; if(i%Min_cycle==0 && i/Min_cycle != 1)///题中说了循环k次, k > 1的 printf("%d %d\n", i, i/Min_cycle); } printf("\n"); } return 0; }
原文:http://www.cnblogs.com/zhengguiping--9876/p/4835334.html