标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 889 Accepted Submission(s): 425
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long ll; const int maxn=2; int x,mod,c; ll m; struct Matrix { int a[maxn][maxn]; Matrix(){memset(a,0,sizeof(a));} Matrix operator* (const Matrix &p) { Matrix res; for(int i=0;i<maxn;i++) { for(int j=0;j<maxn;j++) { for(int k=0;k<maxn;k++) { res.a[i][j]+=(a[i][k]*p.a[k][j]%mod); } res.a[i][j]%=mod; } } return res; } }ans,base; Matrix quick_pow(Matrix base,ll n) { Matrix res; for(int i=0;i<maxn;i++) { res.a[i][i]=1; } while(n) { if(n&1) res=res*base; base=base*base; n>>=1; } return res; } void init_matrix() { ans.a[0][0]=x; ans.a[0][1]=x; ans.a[1][0]=0; ans.a[1][1]=0; base.a[0][0]=10; base.a[0][1]=0; base.a[1][0]=1; base.a[1][1]=1; } int main() { int t,cas=0; scanf("%d",&t); while(t--) { cas++; scanf("%d%lld%d%d",&x,&m,&mod,&c); init_matrix(); ans=ans*quick_pow(base,m-1); printf("Case #%d:\n",cas); if(ans.a[0][0]==c) printf("Yes\n"); else printf("No\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/PrimeXuan/p/5520969.html