Description
GW is Zufe's God Ben, one day he thought of a magical transformation, and named it the GW transformation
For a number n, the value of the transformed GW (n) is, shilling x=n
The first step, if X is single digit, GW (n) =x, otherwise perform the second step;
In the second step, the number of the odd position of X is the sum of a, even position and B, x=a*b, the first step is performed;
Now that we have a T-query, enter three integers for each query l,r,x
For each query, output how many of the numbers in the closed interval of [l,r] are x after the transformation
Input
The first line is a T, which indicates that there is a T Group Inquiry (T<=1000)
Next T line, three integers per line l,r,x (0<=l<=r<=10000000)
Output
The output T line, an integer per line, represents the answer.
Sample Input21 20Sample Output12HINT
The values for the second sample that meet the criteria are 20 and 25, respectively.
offline Operation
#include <cstdio>#include<cstring>#include<cmath>#include<stack>#include<queue>#include<algorithm>using namespacestd;inttot[Ten];intans[ ++Ten];intT;intgw[10000000+Ten];intr[ +],d; structquary{BOOLFlag//Flag==0 says it's the starting point, flag==1 means the end . intT//Group of Inquiries intu; intX//to inquire about numbers}q[ -+Ten]; BOOLcmpConstQuary&a,Constquary&b) { if(A.U==B.U)returna.flag<B.flag; returna.u<b.u;} voidinit () {memset (tot,0,sizeoftot); memset (ans,0,sizeofans);} intTra (intx) {D=0; intA=0, b=0; while(x) {r[d]=x%Ten; X=x/Ten; D++; } for(intI=0; i<d;i++) { if(i%2==0) a=a+R[i]; Elseb=b+R[i]; } returnA *B;} voidF () { for(intI=0; i<=9; i++) gw[i]=i; for(intI=Ten; i<=10000000; i++) gw[i]=Gw[tra (i)];} intMain () {F (); scanf ("%d",&T); Init (); intzzt=0; for(intI=1; i<=t;i++) { intl,r,x; scanf ("%d%d%d",&l,&r,&X); if(x>9|| x<0) {ans[i]=0;Continue;} Q[zzt].flag=0; Q[ZZT].T=i; Q[ZZT].U=m; q[zzt].x=y; ZZT++; Q[zzt].flag=1; Q[ZZT].T=i; Q[ZZT].U=R; q[zzt].x=y; ZZT++; } sort (Q,q+zzt,cmp); intnow=0; for(intI=0; i<zzt;i++) { if(q[i].flag==0) { for(intj=now;j<q[i].u;j++) tot[gw[j]]++; ANS[Q[I].T]=tot[q[i].x]; now=q[i].u; } Else if(q[i].flag==1) { for(intj=now;j<=q[i].u;j++) tot[gw[j]]++; ANS[Q[I].T]=tot[q[i].x]-ans[q[i].t]; now=q[i].u+1; } } for(intI=1; i<=t;i++) printf ("%d\n", Ans[i]); return 0;}
Zufe OJ 2301 GW I (3)