QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#389155 | #7954. Special Numbers | FOY# | WA | 0ms | 3856kb | C++23 | 1.2kb | 2024-04-14 03:40:13 | 2024-04-14 03:40:14 |
Judging History
answer
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
void fix(ll &i) {
i %= mod;
if (i < 0) i += mod;
i %= mod;
}
ll count(ll k, string up) {
map<ll, ll> hi, lo;
for (int i = 1; i < up[0]-'0'; i++) {
lo[gcd(i, k)%k] += 1;
}
hi[gcd(up[0]-'0', k)%k] += 1;
for (int i = 1; i < up.size(); i++) {
map<ll, ll> nhi, nlo;
for (int j = 0; j <= 9; j++) {
for (auto [g, cnt] : hi) {
if (j == up[i]-'0') {
fix(nhi[gcd(g*j, k)%k] += cnt);
}
else if (j < up[i] -'0') {
fix(nlo[gcd(g*j, k)%k] += cnt);
}
}
for (auto [g, cnt] : lo) {
fix(nlo[gcd(g*j, k)%k] += cnt);
}
}
hi = nhi;
lo = nlo;
}
return (hi[0] + lo[0])%mod;
}
ll countAll(ll k, string r) {
ll out = count(k, r);
string s = "9";
while (s.size() < r.size()) {
fix(out += count(k, s));
s.push_back('9');
}
return out;
}
int main() {
ll k; cin >> k;
string l, r; cin >> l >> r;
ll out = countAll(k, r);
if (l != "1") {
int i = l.size()-1;
while (l[i] == '0') {
l[i] = '9';
i--;
}
l[i]--;
fix(out -= countAll(k, l));
}
cout << out << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3856kb
input:
1 100 100000
output:
99801
result:
wrong answer 1st lines differ - expected: '99901', found: '99801'