QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#302376 | #7954. Special Numbers | PetroTarnavskyi# | WA | 1ms | 3628kb | C++20 | 1.9kb | 2024-01-10 20:08:51 | 2024-01-10 20:08:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int LOG = 20;
VI digits;
LL dpT1[LOG][2][2][2];
LL dp1(int pos, int prefd, int eq, int has1)
{
if(pos == SZ(digits))
return has1;
if(dpT1[pos][prefd][eq][has1] != -1)
return dpT1[pos][prefd][eq][has1];
int mx = 10;
if(eq)
mx = digits[pos] + 1;
LL res = 0;
FOR(cur, 0, mx)
res += dp1(pos + 1, prefd || (cur != 0), eq && (cur == digits[pos]), has1 || (prefd && (cur == 0)));
return dpT1[pos][prefd][eq][has1] = res;
}
map<LL, LL> dpT2[LOG][2];
LL dp2(int pos, int eq, LL k)
{
if(pos == SZ(digits))
return (k == 1);
if(dpT2[pos][eq].count(k))
return dpT2[pos][eq][k];
int mx = 10;
if(eq)
mx = digits[pos] + 1;
LL res = 0;
FOR(cur, 1, mx)
res += dp2(pos + 1, eq & (cur == digits[pos]), k / gcd(k, cur));
return dpT2[pos][eq][k] = res;
}
LL solve(LL k, LL n)
{
if(n == 0)
return 0;
digits.clear();
FOR(i, 0, LOG)
FOR(j, 0, 2)
{
FOR(l, 0, 2)
FOR(m, 0, 2)
dpT1[i][j][l][m] = -1;
dpT2[i][j].clear();
}
while(n)
{
digits.PB(n % 10);
n /= 10;
}
reverse(ALL(digits));
LL ans = dp1(0, 0, 1, 0);
ans += dp2(0, 1, k);
FOR(i, 1, SZ(digits))
ans += dp2(i, 0, k);
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
LL k, l, r;
cin >> k >> l >> r;
LL ans = solve(k, r) - solve(k, l - 1);
int mod = 1e9 + 7;
cout << (ans % mod) << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3400kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3408kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3392kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3412kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3496kb
input:
1125899906842624 1 100000000000000000000
output:
566570801
result:
wrong answer 1st lines differ - expected: '555058180', found: '566570801'