QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760162 | #7954. Special Numbers | LittlePants | WA | 90ms | 7508kb | C++14 | 3.5kb | 2024-11-18 15:14:59 | 2024-11-18 15:15:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define X first
#define Y second
#define F first
#define S second
#define vi vector<int>
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(ALL(x), v)
#define ub(x, v) upper_bound(ALL(x), v)
#define re(x) reverse(ALL(x))
#define uni(x) x.resize(unique(ALL(x)) - x.begin())
#define inf 1000000000
#define INF 1000000000000000000
#define mod 1000000007
#define MOD 998244353
#define get_bit(x, y) ((x>>y)&1)
#define mkp make_pair
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cerr << a << ' ', abc(b...);
}
#ifdef debug
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
template<class T> bool ckmin(T& a, const T& b) { return b<a ? a=b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a<b ? a=b, 1 : 0; }
const vector<int> prime = {2, 3, 5, 7};
vector<vector<int>> states;
map<pair<int, vector<int>>, ll> dp;
vector<int> fac;
ll goal;
vector<int> add_fac(const vector<int> &cur_fac, int x) {
vector<int> res(5);
if (cur_fac[4] == 1) return cur_fac;
if (x == 0) {
res[4] = 1;
return res;
}
for (int i = 0; i < 4; i++) {
int j = prime[i], cnt = 0;
while (x % j == 0) {
x /= j;
cnt++;
}
res[i] = min(fac[i], cur_fac[i] + cnt);
}
return res;
}
ll dfs(int pos, vector<int> cur_fac, bool lim, bool lead, const vector<int> &num) {
if (pos == -1) return cur_fac[4] == 1 || cur_fac == fac;
if (!lim && !lead && dp.find(mkp(pos, cur_fac)) != dp.end()) return dp[mkp(pos, cur_fac)];
int ub = (lim ? num[pos] : 9);
ll res = 0;
if (lead) res = (res + dfs(pos - 1, cur_fac, 0, 1, num)) % mod;
for (int i = lead; i <= ub; i++) {
auto nxt = add_fac(cur_fac, i);
res = (res + dfs(pos - 1, nxt, lim && i == ub, 0, num)) % mod;
}
if (!lim && !lead) dp[mkp(pos, cur_fac)] = res;
//test(pos, cur_fac[0], res);
return res;
}
ll cal(__int128 x) {
vector<int> num;
int dig_cnt = 0;
while (x) {
num.eb(x % 10); x /= 10;
dig_cnt++;
}
test(dig_cnt);
vector<int> cur_fac(5);
return dfs(dig_cnt - 1, cur_fac, 1, 1, num);
}
void get_allstates(int pos, vector<int> cur = {}) {
if (pos == 4) {
states.eb(cur);
return;
}
for (int i = 0; i <= fac[pos]; i++) {
cur.eb(i);
get_allstates(pos + 1, cur);
cur.pop_back();
}
}
inline void solve() {
ll k;
cin >> k;
string sl, sr;
cin >> sl >> sr;
fac.resize(5, 0);
ll pk = k;
for (int i = 0; i < 4; i++) {
ll j = prime[i];
while (k % j == 0) {
k /= j;
fac[i]++;
}
}
if (fac[0] + fac[1] + fac[2] + fac[3] == 0) {
fac[4] = -1;
} else {
fac[4] = 0;
}
test(fac[0], fac[1], fac[2], fac[3]);
//get_allstates(0);
//test(SZ(states));
__int128 l = 0, r = 0;
for (int i = 0; i < SZ(sl); i++)
l = l * 10 + (sl[i] - '0');
for (int i = 0; i < SZ(sr); i++)
r = r * 10 + (sr[i] - '0');
//long long lll = l, rrr = r;
//test(lll, rrr);
if (pk == 1) {
ll ans = (r - l + 1);
cout << ans << '\n';
} else {
cout << (cal(r) - cal(l - 1) + mod) % mod;
}
//test(cal(r));
//test(cal(l - 1));
}
signed main() {
IO;
solve();
}
详细
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: 3584kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
1125899906842624 1 100000000000000000000
output:
555058180
result:
ok single line: '555058180'
Test #8:
score: 0
Accepted
time: 4ms
memory: 3748kb
input:
187500000 5941554024261918062 17356601866920567143
output:
679191360
result:
ok single line: '679191360'
Test #9:
score: 0
Accepted
time: 4ms
memory: 3752kb
input:
1555848 157165614890794026 49792374427566422833
output:
588832126
result:
ok single line: '588832126'
Test #10:
score: 0
Accepted
time: 45ms
memory: 6172kb
input:
53814924637488000 8378901287491856069 46225409092942057365
output:
964965504
result:
ok single line: '964965504'
Test #11:
score: 0
Accepted
time: 90ms
memory: 7508kb
input:
11814720750000000 8152927138245188051 35351923956338524619
output:
183963359
result:
ok single line: '183963359'
Test #12:
score: 0
Accepted
time: 32ms
memory: 5304kb
input:
6453888000000 4334845344448208535 35982793193772682339
output:
570114022
result:
ok single line: '570114022'
Test #13:
score: 0
Accepted
time: 40ms
memory: 5708kb
input:
90071357282285400 7893548167754114409 27099084703937108974
output:
869822186
result:
ok single line: '869822186'
Test #14:
score: 0
Accepted
time: 51ms
memory: 6116kb
input:
45571065750000 177160749596350425 98884377930460959454
output:
607698665
result:
ok single line: '607698665'
Test #15:
score: 0
Accepted
time: 27ms
memory: 4916kb
input:
1128443962982400 6338876482181492537 40931938533793596007
output:
881168270
result:
ok single line: '881168270'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 20ms
memory: 4508kb
input:
1412793457031250 2410155470167050095 99063185266833009818
output:
399813226
result:
ok single line: '399813226'
Test #18:
score: 0
Accepted
time: 56ms
memory: 6220kb
input:
67722117120000 8909573534349989418 73129289758235281558
output:
898227227
result:
ok single line: '898227227'
Test #19:
score: 0
Accepted
time: 22ms
memory: 4624kb
input:
472055808000 6809917603531307093 27494416416722163137
output:
379198478
result:
ok single line: '379198478'
Test #20:
score: 0
Accepted
time: 22ms
memory: 4872kb
input:
19353600000 8687492345912514346 24058039408337150852
output:
250715555
result:
ok single line: '250715555'
Test #21:
score: 0
Accepted
time: 14ms
memory: 4200kb
input:
47855420020225440 6150828649270625443 84863934988301168136
output:
665186711
result:
ok single line: '665186711'
Test #22:
score: 0
Accepted
time: 11ms
memory: 4424kb
input:
1382400000 9545797804645162278 70441077437727026904
output:
278230087
result:
ok single line: '278230087'
Test #23:
score: 0
Accepted
time: 4ms
memory: 3884kb
input:
816293376 2952089614708276156 10939708785225040670
output:
120954190
result:
ok single line: '120954190'
Test #24:
score: 0
Accepted
time: 2ms
memory: 3816kb
input:
4185097875 1348426133484952253 56617823359794500344
output:
773995224
result:
ok single line: '773995224'
Test #25:
score: 0
Accepted
time: 17ms
memory: 4408kb
input:
5828945117184 7777082394971366991 63470232991138132969
output:
678496908
result:
ok single line: '678496908'
Test #26:
score: 0
Accepted
time: 12ms
memory: 4432kb
input:
16184770560 3869053219872876321 94590086601168840932
output:
168181821
result:
ok single line: '168181821'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
2 1 12
output:
6
result:
ok single line: '6'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
30146484375 290228705524339176 51853415145287716863
output:
229436627
result:
ok single line: '229436627'
Test #29:
score: 0
Accepted
time: 30ms
memory: 4960kb
input:
2072513819443200 3726664558969607832 42501102605103061370
output:
947952932
result:
ok single line: '947952932'
Test #30:
score: 0
Accepted
time: 65ms
memory: 6988kb
input:
9920232000000000 4602219263214498291 80783137037024823899
output:
846877519
result:
ok single line: '846877519'
Test #31:
score: 0
Accepted
time: 24ms
memory: 5216kb
input:
97200000000000000 9310820760839688870 35322929083473756214
output:
936587432
result:
ok single line: '936587432'
Test #32:
score: 0
Accepted
time: 3ms
memory: 3900kb
input:
45209390625 5752361069878044328 64635325028527078951
output:
578047592
result:
ok single line: '578047592'
Test #33:
score: 0
Accepted
time: 79ms
memory: 7004kb
input:
54442233216000 2452030574225118723 90982734056131320662
output:
417646585
result:
ok single line: '417646585'
Test #34:
score: 0
Accepted
time: 22ms
memory: 4640kb
input:
1530550080000 7431421026778839808 84825282227911272129
output:
600103842
result:
ok single line: '600103842'
Test #35:
score: 0
Accepted
time: 43ms
memory: 5588kb
input:
13765147361280 4924477486471254843 10002324705150566233
output:
951883713
result:
ok single line: '951883713'
Test #36:
score: 0
Accepted
time: 38ms
memory: 5564kb
input:
59825698242187500 6303744363677706767 91410210495502213963
output:
774734375
result:
ok single line: '774734375'
Test #37:
score: 0
Accepted
time: 52ms
memory: 5940kb
input:
110658879959040 2133591391458550040 48494371567095341228
output:
103505650
result:
ok single line: '103505650'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1 3 100
output:
98
result:
ok single line: '98'
Test #39:
score: 0
Accepted
time: 50ms
memory: 5784kb
input:
3160365465600 8968721517098518892 78444481529635953131
output:
364620926
result:
ok single line: '364620926'
Test #40:
score: -100
Wrong Answer
time: 1ms
memory: 3580kb
input:
54838448056132899 4242999884713464056 92948071680698209741
output:
60011844
result:
wrong answer 1st lines differ - expected: '922087167', found: '60011844'