题意:
每一个power前缀的周期数(>1).
思路:
kmp的next. 每一个前缀都询问一遍.
#include <cstring> #include <cstdio> const int MAXN = 1000005; int next[MAXN]; char s[MAXN]; //93MS 5092K void prekmp() { next[0] = -1; int j = -1; for(int i=1;s[i];i++) { while(j!=-1 && s[j+1]!=s[i]) j = next[j]; if(s[j+1]==s[i]) j++; next[i] = j; } } int main() { int n,cas = 0; while(scanf("%d",&n) && n) { scanf("%s",s); printf("Test case #%d ",++cas); prekmp(); int len; for(int i=1;i<n;i++) { len = i-next[i]; int k; if(!((i+1)%len)) { if((k=(i+1)/len)>1) printf("%d %d ",i+1,k); } } printf(" "); } }