HDU 5690 All X 暴力循环节
分析:暴力找循环节就好了
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <string> #include <stack> #include <vector> #include <map> #include <queue> #include <algorithm> #include <utility> using namespace std; typedef long long LL; const int N=1e4+5; const int INF=0x3f3f3f3f; const LL mod=1e9+7; bool vis[N]; int cur[N*2]; int main() { int T,cas=0; scanf("%d",&T); while(T--){ LL x,m,k,c; scanf("%I64d%I64d%I64d%I64d",&x,&m,&k,&c); LL t=0,cnt=1; bool flag=0; memset(vis,0,sizeof(vis)); for(;;++cnt){ t=t*10+x; if(vis[t%k]){flag=1;break;} vis[t%k]=1;cur[cnt]=t%k; t%=k; } if(flag){m%=cnt;if(m==0)m=cnt;} printf("Case #%d:\n",++cas); if(cur[m]==c)printf("Yes\n"); else printf("No\n"); } return 0; }