All X
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 889 Accepted Submission (s): 425
Problem DescriptionF(x,m) Representing a whole is made up of numbersxComposed ofmBit number. Please calculate whether the following formula is true:
F(x,m) mod k ≡ c
Input first line an integerTSaidTGroup data.
One row for each set of test data, containing four digitsx,m,K,c
1≤x≤9
1≤m≤ten
0≤c<k≤
idea: As Xxxxx=x+10*x+100*x+1000*x+10000*x, this is a geometric series with 10 as the male ratio, can construct the matrix to perform the operation[x,x]*[10,0][0,0] [1, 1]
#include <iostream>#include<cstdio>#include<cstring>using namespaceStd;typedefLong Longll;Const intmaxn=2;intx,mod,c;ll m;structmatrix{intA[MAXN][MAXN]; Matrix () {memset (A,0,sizeof(a));} Matrixoperator* (ConstMatrix &p) {Matrix res; for(intI=0; i<maxn;i++) { for(intj=0; j<maxn;j++) { for(intk=0; k<maxn;k++) {Res.a[i][j]+ = (a[i][k]*p.a[k][j]%MoD); } Res.a[i][j]%=MoD; } } returnRes; }}ans,Base; Matrix Quick_pow (MatrixBase, ll N) {Matrix res; for(intI=0; i<maxn;i++) {Res.a[i][i]=1; } while(n) {if(n&1) res=res*Base; Base=Base*Base; N>>=1; } returnRes;}voidInit_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]=Ten; Base. a[0][1]=0; Base. a[1][0]=1; Base. a[1][1]=1;}intMain () {intt,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"); Elseprintf"no\n"); } return 0;}
Baidu Star Preliminary 2A 1001 all X (HDU 5690)