QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322649 | #7954. Special Numbers | NYCU_CartesianTree# | WA | 211ms | 20080kb | C++20 | 8.1kb | 2024-02-07 13:54:16 | 2024-02-07 13:54:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pb push_back
#define ld double
int dp[61][41][21][21][21][2][2], tot[61][41][21][21][21][2][2]; // 2, 3, 5, 7, 0, small, hav
int p2=0, p3=0, p5=0, p7=0;
int g2=0, g3=0, g5=0, g7=0;
const int mol=1e9+7;
void add(int &t1, int t2){
t1+=t2;
t1%=mol;
}
void add1(int j, int t1, int t2, int t3, int t4, int t5){
int op=0;
for(int i=0;i<2;i++) for(int j=0;j<2;j++) op+=dp[t1][t2][t3][t4][t5][i][j];
if(j==0) add(tot[t1][t2][t3][t4][t5+1][1][1], dp[t1][t2][t3][t4][t5][0][1] + dp[t1][t2][t3][t4][t5][1][1])
, add(tot[t1][t2][t3][t4][t5][1][0], dp[t1][t2][t3][t4][t5][1][0] + dp[t1][t2][t3][t4][t5][0][0]);
if(j==1) add(tot[t1][t2][t3][t4][t5][1][1], op);
if(j==2) add(tot[min(t1+1,p2)][t2][t3][t4][t5][1][1],op);
if(j==3) add(tot[t1][min(t2+1, p3)][t3][t4][t5][1][1],op);
if(j==4) add(tot[min(t1+2, p2)][t2][t3][t4][t5][1][1],op);
if(j==5) add(tot[t1][t2][min(t3+1, p5)][t4][t5][1][1],op);
if(j==6) add(tot[min(t1+1, p2)][min(t2+1, p3)][t3][t4][t5][1][1],op);
if(j==7) add(tot[t1][t2][t3][min(t4+1, p7)][t5][1][1],op);
if(j==8) add(tot[min(t1+3, p2)][t2][t3][t4][t5][1][1],op);
if(j==9) add(tot[t1][min(t2+2, p3)][t3][t4][t5][1][1],op);
}
void add2(int j, int t1, int t2, int t3, int t4, int t5){
int op1=0, op2=0;
for(int i=0;i<2;i++) op1+=dp[t1][t2][t3][t4][t5][0][i], op2+=dp[t1][t2][t3][t4][t5][1][i];
// if(t1==0&&t2==0&&t3==0&&t4==0&&t5==0) cerr<<dp[t1][t2][t3][t4][t5][1][1]<<"kk\n";
if(j==0) add(tot[t1][t2][t3][t4][t5+1][1][1], dp[t1][t2][t3][t4][t5][1][1]), add(tot[t1][t2][t3][t4][t5][1][0], dp[t1][t2][t3][t4][t5][1][0]);
if(j==1) add(tot[t1][t2][t3][t4][t5][1][1], op2);
if(j==2) add(tot[min(t1+1, p2)][t2][t3][t4][t5][1][1], op2);
if(j==3) add(tot[t1][min(t2+1, p3)][t3][t4][t5][1][1], op2);
if(j==4) add(tot[min(t1+2, p2)][t2][t3][t4][t5][1][1], op2);
if(j==5) add(tot[t1][t2][min(t3+1, p5)][t4][t5][1][1], op2);
if(j==6) add(tot[min(t1+1, p2)][min(t2+1, p3)][t3][t4][t5][1][1], op2);
if(j==7) add(tot[t1][t2][t3][min(t4+1, p7)][t5][1][1], op2);
if(j==8) add(tot[min(t1+3, p2)][t2][t3][t4][t5][1][1], op2);
if(j==9) add(tot[t1][min(t2+2, p3)][t3][t4][t5][1][1], op2);
if(j==0) add(tot[t1][t2][t3][t4][t5+1][0][1], dp[t1][t2][t3][t4][t5][0][1]), add(tot[t1][t2][t3][t4][t5][0][0], dp[t1][t2][t3][t4][t5][0][0]);
if(j==1) add(tot[t1][t2][t3][t4][t5][0][1], op1);
if(j==2) add(tot[min(t1+1, p2)][t2][t3][t4][t5][0][1], op1);
if(j==3) add(tot[t1][min(t2+1, p3)][t3][t4][t5][0][1], op1);
if(j==4) add(tot[min(t1+2, p2)][t2][t3][t4][t5][0][1], op1);
if(j==5) add(tot[t1][t2][min(t3+1, p5)][t4][t5][0][1], op1);
if(j==6) add(tot[min(t1+1, p2)][min(t2+1, p3)][t3][t4][t5][0][1], op1);
if(j==7) add(tot[t1][t2][t3][min(t4+1, p7)][t5][0][1], op1);
if(j==8) add(tot[min(t1+3, p2)][t2][t3][t4][t5][0][1], op1);
if(j==9) add(tot[t1][min(t2+2, p3)][t3][t4][t5][0][1], op1);
}
void add3(int j, int t1, int t2, int t3, int t4, int t5){
int op2=0;
for(int i=0;i<2;i++) op2+=dp[t1][t2][t3][t4][t5][1][i];
// if(t1+t2+t3+t4+t5==0&&j==5)
// cerr<<op2<<"op\n"<<min(t3+1, p5)<<"\n"<<t3<<" "<<p3<<"\n";
if(j==0) add(tot[t1][t2][t3][t4][t5+1][1][1], dp[t1][t2][t3][t4][t5][1][1]), add(tot[t1][t2][t3][t4][t5][1][0], dp[t1][t2][t3][t4][t5][1][0]);
if(j==1) add(tot[t1][t2][t3][t4][t5][1][1], op2);
if(j==2) add(tot[min(t1+1, p2)][t2][t3][t4][t5][1][1], op2);
if(j==3) add(tot[t1][min(t2+1, p3)][t3][t4][t5][1][1], op2);
if(j==4) add(tot[min(t1+2, p2)][t2][t3][t4][t5][1][1], op2);
if(j==5) add(tot[t1][t2][min(t3+1, p5)][t4][t5][1][1], op2);
if(j==6) add(tot[min(t1+1, p2)][min(t2+1, p3)][t3][t4][t5][1][1], op2);
if(j==7) add(tot[t1][t2][t3][min(t4+1, p7)][t5][1][1], op2);
if(j==8) add(tot[min(t1+3, p2)][t2][t3][t4][t5][1][1], op2);
if(j==9) add(tot[t1][min(t2+2, p3)][t3][t4][t5][1][1], op2);
}
int k;string l, r;
int ff(int g, int h){
if(h==0) return 1;
if(h==1) return g;
if(h%2) return g*ff(g,h-1)%k;
else {
int t=ff(g, h/2);
return t*t%k;
}
}
int calc(__int128 x,int k){
string now;
if(x==0) return 0;
while(x) now+=(char)('0'+x%10), x/=10;
for(int i2=0;i2<=p2;i2++){
for(int i3=0;i3<=p3;i3++){
for(int i5=0;i5<=p5;i5++){
for(int i7=0;i7<=p7;i7++){
for(int i0=0;i0<=20;i0++){
for(int u1=0;u1<2;u1++){
for(int u2=0;u2<2;u2++)
dp[i2][i3][i5][i7][i0][u1][u2]=0;
}
}
}
}
}
}
dp[0][0][0][0][0][0][0]=1;
for(int i=now.size()-1;i>=0;i--){
for(int i2=0;i2<=p2;i2++){
for(int i3=0;i3<=p3;i3++){
for(int i5=0;i5<=p5;i5++){
for(int i7=0;i7<=p7;i7++){
for(int i0=0;i0<=20;i0++){
for(int j=0;j<=9;j++){
if(j<now[i]-'0'){
add1(j, i2, i3, i5, i7, i0);
}
else if(j==now[i]-'0'){
add2(j, i2, i3, i5, i7, i0);
}
else{
add3(j, i2, i3, i5, i7, i0);
}
}
}
}
}
}
}
for(int i2=0;i2<=p2;i2++){
for(int i3=0;i3<=p3;i3++){
for(int i5=0;i5<=p5;i5++){
for(int i7=0;i7<=p7;i7++){
for(int i0=0;i0<=20;i0++){
for(int u1=0;u1<2;u1++){
for(int u2=0;u2<2;u2++)
dp[i2][i3][i5][i7][i0][u1][u2]=tot[i2][i3][i5][i7][i0][u1][u2], tot[i2][i3][i5][i7][i0][u1][u2]=0;
}
}
}
}
}
}
}
// cerr<<dp[0][0][0][0][0][1][0]<<"ff\n";
int now1=0;
for(int i2=0;i2<=p2;i2++){
for(int i3=0;i3<=p3;i3++){
for(int i5=0;i5<=p5;i5++){
for(int i7=0;i7<=p7;i7++){
for(int i0=0;i0<=now.size();i0++){
for(int u1=0;u1<2;u1++){
if(i0) add(now1, dp[i2][i3][i5][i7][i0][u1][1]);
else if(i2>=g2&&i3>=g3&&i5>=g5&&i7>=g7) add(now1, dp[i2][i3][i5][i7][i0][u1][1]);
else break;
// cerr<<dp[i2][i3][i5][i7][i0][u1][1]<<" "<<i2<<" "<<i3<<" "<<i5<<" "<<i7<<" "<<i0<<"\n";
}
}
}
}
}
}
// now1--;
// cerr<<now1<<" "<<now<<"\n";
return now1;
}
void solve(){
cin>>k>>l>>r;
__int128 t1=0, t2=0;
for(auto g:l) t1*=10, t1+=g-'0';
for(auto g:r) t2*=10, t2+=g-'0';
int u1=t2, u2=t1;
// cout<<u1<<" "<<u2<<"\n";
while(u1%2==0) u1/=2, p2++;
while(u1%3==0) u1/=3, p3++;
while(u1%5==0) u1/=5, p5++;
while(u1%7==0) u1/=7, p7++;
int gg=k;
while(gg%2==0) gg/=2, g2++;
while(gg%3==0) gg/=3, g3++;
while(gg%5==0) gg/=5, g5++;
while(gg%7==0) gg/=7, g7++;
p2=g2, p3=g3, p5=g5, p7=g7;
// cerr<<p2<<" "<<p3<<" "<<p5<<" "<<p7<<"\n";
int ans=calc(t2, k);
// p2=0, p3=0, p5=0, p7=0;
// while(u2%2==0) u2/=2, p2++;
// while(u2%3==0) u2/=3, p3++;
// while(u2%5==0) u2/=5, p5++;
// while(u2%7==0) u2/=7, p7++;
ans+=mol-calc(t1-1, k);
ans+=mol;
ans%=mol;
cout<<ans;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;
// cin>>t;
// while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: 0
Accepted
time: 2ms
memory: 4052kb
input:
1125899906842624 1 100000000000000000000
output:
555058180
result:
ok single line: '555058180'
Test #8:
score: 0
Accepted
time: 7ms
memory: 4652kb
input:
187500000 5941554024261918062 17356601866920567143
output:
679191360
result:
ok single line: '679191360'
Test #9:
score: 0
Accepted
time: 6ms
memory: 3872kb
input:
1555848 157165614890794026 49792374427566422833
output:
588832126
result:
ok single line: '588832126'
Test #10:
score: 0
Accepted
time: 131ms
memory: 8288kb
input:
53814924637488000 8378901287491856069 46225409092942057365
output:
964965504
result:
ok single line: '964965504'
Test #11:
score: 0
Accepted
time: 211ms
memory: 15104kb
input:
11814720750000000 8152927138245188051 35351923956338524619
output:
183963359
result:
ok single line: '183963359'
Test #12:
score: 0
Accepted
time: 59ms
memory: 6640kb
input:
6453888000000 4334845344448208535 35982793193772682339
output:
570114022
result:
ok single line: '570114022'
Test #13:
score: 0
Accepted
time: 98ms
memory: 7256kb
input:
90071357282285400 7893548167754114409 27099084703937108974
output:
869822186
result:
ok single line: '869822186'
Test #14:
score: 0
Accepted
time: 93ms
memory: 9800kb
input:
45571065750000 177160749596350425 98884377930460959454
output:
607698665
result:
ok single line: '607698665'
Test #15:
score: 0
Accepted
time: 65ms
memory: 13424kb
input:
1128443962982400 6338876482181492537 40931938533793596007
output:
881168270
result:
ok single line: '881168270'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 42ms
memory: 7160kb
input:
1412793457031250 2410155470167050095 99063185266833009818
output:
399813226
result:
ok single line: '399813226'
Test #18:
score: 0
Accepted
time: 119ms
memory: 14608kb
input:
67722117120000 8909573534349989418 73129289758235281558
output:
898227227
result:
ok single line: '898227227'
Test #19:
score: 0
Accepted
time: 46ms
memory: 6132kb
input:
472055808000 6809917603531307093 27494416416722163137
output:
379198478
result:
ok single line: '379198478'
Test #20:
score: 0
Accepted
time: 43ms
memory: 7696kb
input:
19353600000 8687492345912514346 24058039408337150852
output:
250715555
result:
ok single line: '250715555'
Test #21:
score: 0
Accepted
time: 32ms
memory: 4572kb
input:
47855420020225440 6150828649270625443 84863934988301168136
output:
665186711
result:
ok single line: '665186711'
Test #22:
score: 0
Accepted
time: 16ms
memory: 7104kb
input:
1382400000 9545797804645162278 70441077437727026904
output:
278230087
result:
ok single line: '278230087'
Test #23:
score: 0
Accepted
time: 8ms
memory: 4832kb
input:
816293376 2952089614708276156 10939708785225040670
output:
120954190
result:
ok single line: '120954190'
Test #24:
score: 0
Accepted
time: 7ms
memory: 4172kb
input:
4185097875 1348426133484952253 56617823359794500344
output:
773995224
result:
ok single line: '773995224'
Test #25:
score: 0
Accepted
time: 32ms
memory: 4944kb
input:
5828945117184 7777082394971366991 63470232991138132969
output:
678496908
result:
ok single line: '678496908'
Test #26:
score: 0
Accepted
time: 23ms
memory: 5276kb
input:
16184770560 3869053219872876321 94590086601168840932
output:
168181821
result:
ok single line: '168181821'
Test #27:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
2 1 12
output:
6
result:
ok single line: '6'
Test #28:
score: 0
Accepted
time: 7ms
memory: 4020kb
input:
30146484375 290228705524339176 51853415145287716863
output:
229436627
result:
ok single line: '229436627'
Test #29:
score: 0
Accepted
time: 66ms
memory: 6692kb
input:
2072513819443200 3726664558969607832 42501102605103061370
output:
947952932
result:
ok single line: '947952932'
Test #30:
score: 0
Accepted
time: 174ms
memory: 20080kb
input:
9920232000000000 4602219263214498291 80783137037024823899
output:
846877519
result:
ok single line: '846877519'
Test #31:
score: 0
Accepted
time: 88ms
memory: 17716kb
input:
97200000000000000 9310820760839688870 35322929083473756214
output:
936587432
result:
ok single line: '936587432'
Test #32:
score: 0
Accepted
time: 13ms
memory: 4528kb
input:
45209390625 5752361069878044328 64635325028527078951
output:
578047592
result:
ok single line: '578047592'
Test #33:
score: 0
Accepted
time: 138ms
memory: 11264kb
input:
54442233216000 2452030574225118723 90982734056131320662
output:
417646585
result:
ok single line: '417646585'
Test #34:
score: 0
Accepted
time: 41ms
memory: 10544kb
input:
1530550080000 7431421026778839808 84825282227911272129
output:
600103842
result:
ok single line: '600103842'
Test #35:
score: 0
Accepted
time: 90ms
memory: 8256kb
input:
13765147361280 4924477486471254843 10002324705150566233
output:
951883713
result:
ok single line: '951883713'
Test #36:
score: 0
Accepted
time: 90ms
memory: 8188kb
input:
59825698242187500 6303744363677706767 91410210495502213963
output:
774734375
result:
ok single line: '774734375'
Test #37:
score: 0
Accepted
time: 98ms
memory: 7912kb
input:
110658879959040 2133591391458550040 48494371567095341228
output:
103505650
result:
ok single line: '103505650'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
1 3 100
output:
98
result:
ok single line: '98'
Test #39:
score: 0
Accepted
time: 88ms
memory: 10024kb
input:
3160365465600 8968721517098518892 78444481529635953131
output:
364620926
result:
ok single line: '364620926'
Test #40:
score: -100
Wrong Answer
time: 1ms
memory: 3780kb
input:
54838448056132899 4242999884713464056 92948071680698209741
output:
60011844
result:
wrong answer 1st lines differ - expected: '922087167', found: '60011844'