QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#56919 | #3161. Another Coin Weighing Puzzle | Al0kahde | AC ✓ | 69ms | 5916kb | C++ | 1.1kb | 2022-10-21 21:48:57 | 2022-10-21 21:48:58 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <cstdio>
using ll = long long;
using namespace std;
const int maxn = 1000100, mod = 998244353;
char mu[maxn];
bool notPrime[maxn];
int prime[maxn / 8], pn;
ll qpow(ll N, int po = mod - 2) {
ll cur = 1;
for (; po; po >>= 1) {
if (po & 1) {
cur = cur * N % mod;
}
N = N * N % mod;
}
return cur;
}
void linearSieve(int N) {
notPrime[1] = notPrime[0] = true;
mu[1] = 1;
for (int i = 2; i <= N; i++) {
if (!notPrime[i]) {
prime[pn++] = i;
mu[i] = -1;
}
for (int j = 0; j < pn; j++) {
if ((ll)i * prime[j] > N) break;
notPrime[i * prime[j]] = true;
if (i % prime[j] == 0) {
break;
} else {
mu[i * prime[j]] = mu[i] * mu[prime[j]];
}
}
}
}
inline void cmod(ll &val) {
val %= mod;
if (val < 0)
val += mod;
}
ll ways(int m, int k) {
ll tot = 1;
for (int i = 1; i <= k; i++) {
tot += mu[i] * (qpow(k / i * 2 + 1, m) - 1);
}
cmod(tot);
return tot;
}
int main() {
int m, k;
cin >> m >> k;
linearSieve(k);
ll ans = ways(m, k);
cmod(ans);
cout << ans << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3688kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 4ms
memory: 3708kb
input:
10000 10000
output:
689223145
result:
ok single line: '689223145'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3688kb
input:
9999 31
output:
986106162
result:
ok single line: '986106162'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3712kb
input:
57 9817
output:
447253096
result:
ok single line: '447253096'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
501 499
output:
247755220
result:
ok single line: '247755220'
Test #7:
score: 0
Accepted
time: 13ms
memory: 3988kb
input:
97424 174829
output:
964884269
result:
ok single line: '964884269'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3532kb
input:
11 13
output:
729153057
result:
ok single line: '729153057'
Test #9:
score: 0
Accepted
time: 14ms
memory: 4048kb
input:
200000 200000
output:
803771125
result:
ok single line: '803771125'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
199999 562
output:
865836540
result:
ok single line: '865836540'
Test #11:
score: 0
Accepted
time: 11ms
memory: 4096kb
input:
3539 189423
output:
530738158
result:
ok single line: '530738158'
Test #12:
score: 0
Accepted
time: 8ms
memory: 3968kb
input:
198324 173852
output:
963717515
result:
ok single line: '963717515'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3732kb
input:
1 1
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 69ms
memory: 5916kb
input:
1000000 1000000
output:
800590912
result:
ok single line: '800590912'
Test #15:
score: 0
Accepted
time: 45ms
memory: 5708kb
input:
5034 999999
output:
946555033
result:
ok single line: '946555033'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
999998 2042
output:
713878368
result:
ok single line: '713878368'