QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#301291 | #7954. Special Numbers | tarjen# | RE | 79ms | 634452kb | C++20 | 2.4kb | 2024-01-09 17:20:33 | 2024-01-09 17:20:33 |
Judging History
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;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 28ms
memory: 634136kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 63ms
memory: 634180kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 64ms
memory: 634256kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 79ms
memory: 634452kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 35ms
memory: 634180kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 73ms
memory: 634240kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: -100
Runtime Error
input:
1125899906842624 1 100000000000000000000