QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361246 | #7954. Special Numbers | SolitaryDream | WA | 100ms | 1761080kb | C++17 | 1.5kb | 2024-03-23 01:03:07 | 2024-03-23 01:03:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int P=1e9+7;
int f[22][2][2][63][42][42][23];
string l,r;
int k;
__int128 pw[11][70];
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(!i||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<=62;j++)
pw[i][j]=pw[i][j-1]*i%k;
}
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: 48ms
memory: 1760912kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 67ms
memory: 1761080kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 47ms
memory: 1760860kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 68ms
memory: 1761080kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 64ms
memory: 1760860kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 31ms
memory: 1760972kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: 0
Accepted
time: 100ms
memory: 1760788kb
input:
1125899906842624 1 100000000000000000000
output:
555058180
result:
ok single line: '555058180'
Test #8:
score: -100
Wrong Answer
time: 75ms
memory: 1760852kb
input:
187500000 5941554024261918062 17356601866920567143
output:
812969085
result:
wrong answer 1st lines differ - expected: '679191360', found: '812969085'