题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5690
题意:
题解:找找循环节就行
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<string> 5 #include<set> 6 #include<map> 7 #include<vector> 8 #include<queue> 9 #include<algorithm> 10 #include<functional> 11 #define cl(a,b) memset(a,b,sizeof(a)); 12 #define FFC(i,a,b) for(int i=a;i<=b;++i) 13 #define FFI(i,a,b) for(int i=a;i>=b;--i) 14 #define pb push_back 15 #define LL long long 16 using namespace std; 17 int v[10010],ans[10010]; 18 int main(){ 19 int t,ic=1; 20 scanf("%d",&t); 21 while(t--){ 22 printf("Case #%d: ",ic++); 23 int a,c,k,pre,tmp,cnt,cct;LL m,mm; 24 scanf("%d%I64d%d%d",&a,&m,&k,&c); 25 FFC(i,0,k)v[i]=0; 26 tmp=0,cnt=0,cct=0,mm=-1; 27 while(tmp<=k&&m--)tmp=tmp*10+a; 28 if(tmp<=k){ 29 if(tmp%k==c)puts("Yes"); 30 else puts("no"); 31 continue; 32 } 33 mm=++m,tmp/=10; 34 while(m--){ 35 tmp=tmp*10+a; 36 int ttmp=tmp%k; 37 tmp%=k; 38 if(v[ttmp])break; 39 else v[ttmp]++,cnt++,ans[++cct]=ttmp; 40 } 41 int vv=mm%cnt; 42 if(vv==0)vv=cnt; 43 if(ans[vv]==c)printf("Yes "); 44 else printf("No "); 45 } 46 return 0; 47 }