#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int len;int n = 1000;int next[10000];int f[50000];char s[50000];int Pow (int a, int b) {int res=1; while (b) {if (b&1) res=res*a%7; a=a*a%7; b>>=1; } return res; void GetNext () {int j=0,k=-1; Next[0]=-1; while (j<n) {if (k==-1| | S[j]==s[k]) {next[++j]=++k; } else {k=next[k]; }}}int Main () {for (int i=1;i<=600;i++) {F[i] = F[i-1] + Pow (i,i); f[i]%=7; } for (int i=0;i<=600;i++) {sprintf (&s[i], "%d", f[i]); } s[601]= ' + '; cout<<s<<endl; GetNext (); for (int i=1;i<=600;i++)//By test instructions, a string of length 1 does not count {Len=i-next[i]; Len represents the least-cross-link if (i%len==0 && i/len>1)//cycles greater than 1 is the loop string {cout<< "ans =" <<l en<≪endl; }} printf ("\ n");}
Magical next array to play table to find the smallest link len