Baidu Star Preliminary 2A 1001 all X (HDU 5690)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.