Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5690
Test instructions: M numbers are all x mod k = c; m <= 1010,0 < c,k <= 10,000;
FA 1:xxx = (10m-1)/9*x; but N is too big to be mod. Remove the denominator and change the formula to: 10m*x% (9k)-percent X (9k) =? 9c, of which 10m fast two times power can be;
Time Complexity of O (LOGN)
Method 2: Due to the generation of M x number of mods with a detachable, so the direct solution period can be;
#include <bits/stdc++.h>using namespacestd;#defineRep0 (I,L,R) for (int i = (l); i < (R); i++)#defineREP1 (I,L,R) for (int i = (l); I <= (r); i++)#defineRep_0 (i,r,l) for (int i = (r); i > (l); i--)#defineRep_1 (i,r,l) for (int i = (r); I >= (l); i--)#defineMS0 (a) memset (A,0,sizeof (a))#defineMS1 (a) memset (A,-1,sizeof (a))#defineMSi (a) memset (A,0x3f,sizeof (a))#defineINF 0x3f3f3f3f#defineLson L, M, RT << 1#defineRson m+1, R, RT << 1|1typedef pair<int,int>PII;#defineA First#defineB Second#defineMK Make_pairtypedefLong Longll;typedef unsignedint UINT; template<typename t>voidRead1 (T &m) {T x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} M= x*F;} Template<typename t>voidRead2 (T &a,t &b) {Read1 (a); Read1 (b);} Template<typename t>voidRead3 (T &a,t &b,t &c) {Read1 (a); Read1 (b); Read1 (c);} Template<typename t>void out(T a) {if(a>9) out(ATen); Putchar (A%Ten+'0');}Const intMAXN = 1e4+7;intMP[MAXN], RK[MAXN];intMain () {//freopen ("Data.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout); intT, Kase =1; scanf ("%d",&T); while(t--) {MS1 (MP); ll X, M, K, C, Circle= -1, aux =0, start; Read2 (X,M); Read2 (K,C); REP1 (i,1, M) {aux= (aux*Ten+X)%K; Rk[i]=aux; if(Mp[rk[i]]! =-1) {Circle= i-Mp[rk[i]]; Start=Mp[rk[i]]; Break; } Mp[rk[i]]=i; } //printf ("\n%lld%lld\n\n", start,circle);printf"Case #%d:\n", kase++); if(Circle = =-1) puts (aux= = c?"Yes":"No"); Else{ intAns = rk[(m-start)%circle +start]; Puts (ans= = c?"Yes":"No"); } } return 0;}
HDU 5690 2016 "Baidu Star"-Preliminary round (Astar round2a) all X fast Two power | | Search Cycle