B. Recursive Queries 打表

Code:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
const int maxn=1000000+4;
using namespace std;
void setio(string a){
    freopen((a+".in").c_str(),"r",stdin),freopen((a+".out").c_str(),"w",stdout);
}
int f(int x){
    if(x==0) return 0;
    int rep=1;
    while(x)
    {
        while(x%10==0) x/=10;
        rep*=(x%10);
        x/=10;
    }
    return rep;
}
int g(int x){
    if(x<10) return x;
    return g(f(x));
}
int c[maxn][12];
int main(){
    //setio("input");
    for(int i=1;i<=1000000;++i)
    {
        int x=g(i);
        for(int j=1;j<=9;++j)
        {
            if(x==j) c[i][j]=c[i-1][j]+1;
            else c[i][j]=c[i-1][j];
        }
    }
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int l,r,k;
        scanf("%d%d%d",&l,&r,&k);
        printf("%d\n",c[r][k]-c[l-1][k]);
    }
    return 0;
}
posted @ 2018-10-24 08:24  EM-LGH  阅读(206)  评论(0编辑  收藏  举报