QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301293#7954. Special Numberstarjen#RE 80ms634468kbC++202.4kb2024-01-09 17:23:312024-01-09 17:23:31

Judging History

你现在查看的是最新测评结果

  • [2024-01-09 17:23:31]
  • 评测
  • 测评结果:RE
  • 用时:80ms
  • 内存:634468kb
  • [2024-01-09 17:23:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
istream& operator >> (istream& in, __int128& num) {
    string s;in>>s;
    num=0;
    for(auto it:s)num=num*10+it-'0';
    return in;
}

ostream& operator << (ostream& out, __int128 num) {
    string s;
    do{
        s.push_back(char(num%10+'0'));
        num/=10;
    }while(num>0);
    reverse(s.begin(),s.end());
    out<<s;
    return out;
}
typedef __int128 ll;
void add(int &x,int y){
    if((x+=y)>=mod)x-=mod;
}
void del(int &x,int y){
    if((x-=y)<0)x+=mod;
}
int dp[2][21][80][50][31][31];
int p[25];
void f1(int &a,int &b,int &c,int &d,int x){
    // a=2 b=3 c=5 d=7
    if(x==2)a--;
    if(x==3)b--;
    if(x==4)a-=2;
    if(x==5)c--;
    if(x==6)a--,b--;
    if(x==7)d--;
    if(x==8)a-=3;
    if(x==9)b-=2;
}
void f2(int &a,int &b,int &c,int &d,int x){
    // a=2 b=3 c=5 d=7
    if(x==2)a++;
    if(x==3)b++;
    if(x==4)a+=2;
    if(x==5)c++;
    if(x==6)a++,b++;
    if(x==7)d++;
    if(x==8)a+=3;
    if(x==9)b+=2;
}
int dfs(int flag,int i,int a,int b,int c,int d){
    // if(a<0||b<0||c<0||d<0)return 0;
    if(a<0)a=0;
    if(b<0)b=0;
    if(c<0)c=0;
    if(d<0)d=0;
    if(i==0){
        return (a+b+c+d)!=0;
    }
    if(dp[flag][i][a][b][c][d]!=-1)return dp[flag][i][a][b][c][d];
    int g=9;
    if(flag)g=p[i];
    int res=0;
    for(int x=1;x<=g;x++){
        f1(a,b,c,d,x);
        add(res,dfs(flag&(x==g),i-1,a,b,c,d));
        f2(a,b,c,d,x);
    }
    // cout<<"flag="<<flag<<" i="<<i<<" a="<<a<<" b="<<b<<" c="<<c<<" d="<<d<<" res="<<res<<"\n";
    return dp[flag][i][a][b][c][d]=res;
}
int solve(ll n,int a,int b,int c,int d)
{
    if(n==0)return 0;
    // cout<<"n="<<n<<"\n";
    memset(dp,-1,sizeof(dp));
    int t=0;
    while(n>0){
        t++;
        p[t]=n%10;
        n/=10;
    }
    int res=0;
    for(int i=t-1;i>=1;i--)add(res,dfs(0,i,a,b,c,d));
    add(res,dfs(1,t,a,b,c,d));
    return res;
}
int main()
{   
    long long k;
    ll L,R;
    cin>>k>>L>>R;
    vector<int> cnt;
    for(auto x:{2,3,5,7}){
        int g=0;
        while(k%x==0)k/=x,g++;
        cnt.push_back(g);
    }
    if(k!=1){
        cout<<0<<"\n";
        return 0;
    }
    int ans=(R-L+1)%mod;
    del(ans,solve(R,cnt[0],cnt[1],cnt[2],cnt[3]));
    add(ans,solve(L-1,cnt[0],cnt[1],cnt[2],cnt[3]));
    cout<<ans<<"\n";
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 16ms
memory: 634464kb

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 71ms
memory: 634272kb

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 72ms
memory: 634188kb

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 71ms
memory: 634252kb

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

score: 0
Accepted
time: 27ms
memory: 634136kb

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 80ms
memory: 634468kb

input:

10 800 43021

output:

23570

result:

ok single line: '23570'

Test #7:

score: -100
Runtime Error

input:

1125899906842624 1 100000000000000000000

output:


result: