QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361243 | #7954. Special Numbers | SolitaryDream | WA | 43ms | 172004kb | C++17 | 1.5kb | 2024-03-23 00:55:20 | 2024-03-23 00:55:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int P=1e9+7;
int f[22][2][2][22][22][22][23];
string l,r;
int k;
__int128 pw[11][21];
int dp(int x,int lead,int dw,int up,int c2,int c3,int c5,int c7)
{
if(x==r.size())
{
if(c7==22)
return 1;
__int128 w=pw[2][c2]%k*pw[3][c3]%k*pw[5][c5]%k*pw[7][c7]%k;
return !w;
}
if(f[x][lead][up][c2][c3][c5][c7]!=-1)
return f[x][lead][up][c2][c3][c5][c7];
int &ret=f[x][lead][up][c2][c3][c5][c7];
ret=0;
for(int i=(dw?l[x]-'0':0);i<=(up?r[x]-'0':9);i++)
{
int w=i;
int nlead=lead&&i==0;
int ndw=dw&&i==l[x]-'0';
int nup=up&&i==r[x]-'0';
int nc2=c2,nc3=c3,nc5=c5,nc7=c7;
if(!nlead)
{
if(!w||nc7==22)
nc2=nc3=nc5=nc7=22;
else
{
while(w%2==0)
nc2++,w/=2;
while(w%3==0)
nc3++,w/=3;
while(w%5==0)
nc5++,w/=5;
while(w%7==0)
nc7++,w/=7;
}
}
ret+=dp(x+1,nlead,ndw,nup,nc2,nc3,nc5,nc7);
}
return ret%=P;
}
signed main()
{
cin>>k>>l>>r;
while(l.size()<r.size())
l='0'+l;
for(int i=1;i<=9;i++)
{
pw[i][0]=1;
for(int j=1;j<=20;j++)
pw[i][j]=pw[i][j-1]*i;
}
memset(f,-1,sizeof(f));
cout<<dp(0,1,1,1,0,0,0,0)<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 172004kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 11ms
memory: 171888kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 7ms
memory: 171940kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 8ms
memory: 172000kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 7ms
memory: 171940kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 11ms
memory: 172004kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: -100
Wrong Answer
time: 43ms
memory: 172004kb
input:
1125899906842624 1 100000000000000000000
output:
89095675
result:
wrong answer 1st lines differ - expected: '555058180', found: '89095675'