QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389185 | #7954. Special Numbers | kevinyang# | WA | 352ms | 14132kb | C++17 | 2.8kb | 2024-04-14 04:46:45 | 2024-04-14 04:46:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = (int)1e9+7;
pair<int,int> get(int n, int x){
int v = 0;
while(n%x==0){
v++;
n/=x;
}
return make_pair(n,v);
}
vector<int>p = {2,3,5,7};
vector<int>sz;
int k;
vector<int>factors;
map<int,int>dp[25][2]; // length, equals so far
int solve(string s){
for(int i = 0; i<25; i++){
dp[i][0].clear();
dp[i][1].clear();
}
dp[0][1][1] = 1;
s = " " + s;
for(int t = 1; t<s.size(); t++){
for(int d = 0; d<10; d++){
for(int u: factors){
dp[t][0][__gcd(u*d,k)] += dp[t-1][0][u]; dp[t][0][__gcd(u*d,k)]%=mod;
}
if(t > 1 && d > 0){
dp[t][0][__gcd(d,k)]++;
dp[t][0][__gcd(d,k)]%=mod;
//cout << "upd " << t << ' ' << __gcd(d,k) << ' ' << dp[t][0][__gcd(d,k)] << '\n';
}
}
for(int d = 0; d<=s[t]-'0'; d++){
//cout << "trying " << d << '\n';
if(d==0 && t==1)continue;
if(d<s[t]-'0'){
for(int u: factors){
dp[t][0][__gcd(u*d,k)] += dp[t-1][1][u]; dp[t][0][__gcd(u*d,k)]%=mod;
}
}
else{
for(int u: factors){
dp[t][1][__gcd(u*d,k)] += dp[t-1][1][u]; dp[t][1][__gcd(u*d,k)]%=mod;
}
}
}
}
/*
if(s.size() >= 3)for(auto [a,b] : dp[3][0]){
cout << a << ' ' << b << '\n';
}
if(s.size() >= 3)for(auto [a,b] : dp[2][0]){
cout << a << ' ' << b << ' ' << 1 << '\n';
}
if(s.size() >= 3)for(auto [a,b] : dp[1][0]){
cout << a << ' ' << b << ' ' << -1 << '\n';
}
*/
int ans = dp[s.size()-1][0][k] + dp[s.size()-1][1][k];
//cout << ans << '\n';
return ans%mod;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> k;
int k2 = k;
for(int i = 0; i<4; i++){
auto [nk, cnt] = get(k2,p[i]);
sz.push_back(cnt);
k2 = nk;
}
for(int a = 0; a<=sz[0]; a++){
for(int b = 0; b<=sz[1]; b++){
for(int c = 0; c<=sz[2]; c++){
for(int d = 0; d<=sz[3]; d++){
int v = 1;
for(int i = 0; i<a; i++){
v*=2;
}
for(int i = 0; i<b; i++){
v*=3;
}
for(int i = 0; i<c; i++){
v*=5;
}
for(int i = 0; i<d; i++){
v*=7;
}
factors.push_back(v);
}
}
}
}
sort(factors.begin(),factors.end());
/*
cerr << k2 << '\n';
cerr << "gay\n";
for(int nxt: factors){
cout << nxt << ' ';
}
cout << '\n' << '\n';
*/
if(k2!=1){
cout << "0\n";
return 0;
}
string l,r;
cin >> l >> r;
for(int i = (int)l.size()-1; i>=0; i--){
if(l[i] == '0'){
l[i] = '9';
continue;
}
l[i]--;
break;
}
if(l[0] == '0'){
l.erase(l.begin());
}
if(l.empty()){
cout << solve(r)%mod << '\n';
return 0;
}
int v = solve(r);
int v2 = solve(l);
//cout << v << ' ' << v2 << '\n';
//cout << l << ' ' << r << '\n';
v-=v2;
v%=mod;
v+=mod; v%=mod;
cout << v << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3984kb
input:
1125899906842624 1 100000000000000000000
output:
555058180
result:
ok single line: '555058180'
Test #8:
score: 0
Accepted
time: 8ms
memory: 3996kb
input:
187500000 5941554024261918062 17356601866920567143
output:
679191360
result:
ok single line: '679191360'
Test #9:
score: 0
Accepted
time: 6ms
memory: 3800kb
input:
1555848 157165614890794026 49792374427566422833
output:
588832126
result:
ok single line: '588832126'
Test #10:
score: 0
Accepted
time: 216ms
memory: 10128kb
input:
53814924637488000 8378901287491856069 46225409092942057365
output:
964965504
result:
ok single line: '964965504'
Test #11:
score: 0
Accepted
time: 352ms
memory: 14132kb
input:
11814720750000000 8152927138245188051 35351923956338524619
output:
183963359
result:
ok single line: '183963359'
Test #12:
score: 0
Accepted
time: 95ms
memory: 6648kb
input:
6453888000000 4334845344448208535 35982793193772682339
output:
570114022
result:
ok single line: '570114022'
Test #13:
score: 0
Accepted
time: 159ms
memory: 8408kb
input:
90071357282285400 7893548167754114409 27099084703937108974
output:
869822186
result:
ok single line: '869822186'
Test #14:
score: 0
Accepted
time: 152ms
memory: 8388kb
input:
45571065750000 177160749596350425 98884377930460959454
output:
607698665
result:
ok single line: '607698665'
Test #15:
score: 0
Accepted
time: 85ms
memory: 6356kb
input:
1128443962982400 6338876482181492537 40931938533793596007
output:
881168270
result:
ok single line: '881168270'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 66ms
memory: 5856kb
input:
1412793457031250 2410155470167050095 99063185266833009818
output:
399813226
result:
ok single line: '399813226'
Test #18:
score: 0
Accepted
time: 177ms
memory: 9072kb
input:
67722117120000 8909573534349989418 73129289758235281558
output:
898227227
result:
ok single line: '898227227'
Test #19:
score: 0
Accepted
time: 61ms
memory: 5948kb
input:
472055808000 6809917603531307093 27494416416722163137
output:
379198478
result:
ok single line: '379198478'
Test #20:
score: 0
Accepted
time: 55ms
memory: 5900kb
input:
19353600000 8687492345912514346 24058039408337150852
output:
250715555
result:
ok single line: '250715555'
Test #21:
score: 0
Accepted
time: 48ms
memory: 5252kb
input:
47855420020225440 6150828649270625443 84863934988301168136
output:
665186711
result:
ok single line: '665186711'
Test #22:
score: 0
Accepted
time: 22ms
memory: 4540kb
input:
1382400000 9545797804645162278 70441077437727026904
output:
278230087
result:
ok single line: '278230087'
Test #23:
score: 0
Accepted
time: 9ms
memory: 4004kb
input:
816293376 2952089614708276156 10939708785225040670
output:
120954190
result:
ok single line: '120954190'
Test #24:
score: 0
Accepted
time: 8ms
memory: 3904kb
input:
4185097875 1348426133484952253 56617823359794500344
output:
773995224
result:
ok single line: '773995224'
Test #25:
score: 0
Accepted
time: 44ms
memory: 5176kb
input:
5828945117184 7777082394971366991 63470232991138132969
output:
678496908
result:
ok single line: '678496908'
Test #26:
score: 0
Accepted
time: 34ms
memory: 4876kb
input:
16184770560 3869053219872876321 94590086601168840932
output:
168181821
result:
ok single line: '168181821'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 1 12
output:
6
result:
ok single line: '6'
Test #28:
score: 0
Accepted
time: 9ms
memory: 3940kb
input:
30146484375 290228705524339176 51853415145287716863
output:
229436627
result:
ok single line: '229436627'
Test #29:
score: 0
Accepted
time: 98ms
memory: 6872kb
input:
2072513819443200 3726664558969607832 42501102605103061370
output:
947952932
result:
ok single line: '947952932'
Test #30:
score: 0
Accepted
time: 253ms
memory: 11768kb
input:
9920232000000000 4602219263214498291 80783137037024823899
output:
846877519
result:
ok single line: '846877519'
Test #31:
score: 0
Accepted
time: 126ms
memory: 7872kb
input:
97200000000000000 9310820760839688870 35322929083473756214
output:
936587432
result:
ok single line: '936587432'
Test #32:
score: 0
Accepted
time: 16ms
memory: 4248kb
input:
45209390625 5752361069878044328 64635325028527078951
output:
578047592
result:
ok single line: '578047592'
Test #33:
score: 0
Accepted
time: 207ms
memory: 10588kb
input:
54442233216000 2452030574225118723 90982734056131320662
output:
417646585
result:
ok single line: '417646585'
Test #34:
score: 0
Accepted
time: 49ms
memory: 5564kb
input:
1530550080000 7431421026778839808 84825282227911272129
output:
600103842
result:
ok single line: '600103842'
Test #35:
score: 0
Accepted
time: 124ms
memory: 7844kb
input:
13765147361280 4924477486471254843 10002324705150566233
output:
951883713
result:
ok single line: '951883713'
Test #36:
score: 0
Accepted
time: 144ms
memory: 8440kb
input:
59825698242187500 6303744363677706767 91410210495502213963
output:
774734375
result:
ok single line: '774734375'
Test #37:
score: 0
Accepted
time: 151ms
memory: 8752kb
input:
110658879959040 2133591391458550040 48494371567095341228
output:
103505650
result:
ok single line: '103505650'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 3 100
output:
98
result:
ok single line: '98'
Test #39:
score: 0
Accepted
time: 136ms
memory: 8076kb
input:
3160365465600 8968721517098518892 78444481529635953131
output:
364620926
result:
ok single line: '364620926'
Test #40:
score: -100
Wrong Answer
time: 0ms
memory: 3884kb
input:
54838448056132899 4242999884713464056 92948071680698209741
output:
0
result:
wrong answer 1st lines differ - expected: '922087167', found: '0'