QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#301330 | #7954. Special Numbers | Himeno_Towa# | WA | 1ms | 4064kb | C++20 | 1.8kb | 2024-01-09 17:59:39 | 2024-01-09 17:59:40 |
Judging History
answer
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
inline int mul(int x, int y){return 1ll * x * y % mod;}
inline int add(int x, int y){return x + y >= mod ? x + y - mod : x + y;}
inline int minus(int x, int y){return x < y ? x - y + mod : x - y;}
long long k;
int lenl, lenr, a[25];
char l[25], r[25];
std::unordered_map <long long, int> dp[25][2];
inline long long t(long long x){return std::__gcd(x, k) % k;}
int cal(char s[]){
int len = strlen(s);
if(len == 1 && s[0] == '0') return 0;
for(int i = 0; i < len; ++i) a[i] = s[i] - '0';
for(int i = 0; i < len; ++i) dp[i][0].clear(), dp[i][1].clear();
for(int i = 1; i < a[len - 1]; ++i) dp[len - 1][1][t(i)]++;
dp[len - 1][0][t(a[len - 1])]++;
for(int i = len - 2; i >= 0; --i){
for(int j = 1; j <= 9; ++j) dp[i][1][t(j)]++;
for(auto [u, v]: dp[i + 1][0])
for(int o = 0; o <= 9; ++o){
if(o > a[i]) continue;
int nxt = 0; if(o < a[i]) nxt = 1; long long x = t(u * o);
dp[i][nxt][x] = add(dp[i][nxt][x], v);
}
for(auto [u, v]: dp[i + 1][1])
for(int o = 0; o <= 9; ++o){
long long x = t(u * o);
dp[i][1][x] = add(dp[i][1][x], v);
}
}
int res = 0;
for(int i = 0; i <= 1; ++i) res = add(res, dp[0][i][0]);
return res;
}
int main(){
scanf("%lld%s%s", &k, l, r);
lenl = strlen(l), lenr = strlen(r);
std::reverse(l, l + lenl);
std::reverse(r, r + lenr);
long long kk = k;
for(int i = 2; i <= 9; ++i){
if(kk % i == 0){
while(kk % i == 0){
kk /= i;
}
}
}
if(kk != 1ll){
printf("0\n");
return 0;
}
--l[0]; int now = 0;
while(now < lenl && l[now] < '0') l[now] += 10, --l[++now];
printf("%d\n", minus(cal(r), cal(l)));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4064kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3804kb
input:
1 100 100000
output:
99801
result:
wrong answer 1st lines differ - expected: '99901', found: '99801'