QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#108465 | #3161. Another Coin Weighing Puzzle | zaxwellmen# | AC ✓ | 161ms | 19100kb | C++20 | 1.1kb | 2023-05-25 04:02:24 | 2023-05-25 04:02:26 |
Judging History
answer
#include <vector>
#include <iostream>
#define MOD 998244353
#define MAXN 1000000
using namespace std;
int m, k;
long long dp[1000001];
long long mpowers[1000001];
int main(){
cin >> m >> k;
long long power2[21];
dp[0] = 0;
for(int i = 1; i <= 2 * MAXN + 1; i += 2){
power2[0] = i;
for(int j = 1; j < 21; j++){
power2[j] = (power2[j - 1] * power2[j - 1]) % MOD;
}
int t = m;
long long ans = 1;
for(int j = 0; j < 21; j++){
if(t % 2 == 1){
ans *= power2[j];
ans %= MOD;
}
t/=2;
}
mpowers[i/2] = ans;
if(i > 1){
dp[i/2] = (MOD + mpowers[i/2] - mpowers[i/2 - 1]) % MOD;
}
}
for(int i = 1; i <= MAXN; i++){
int j = 2;
while(i * j <= MAXN){
dp[i * j] += (MOD - dp[i]);
dp[i * j] %= MOD;
j++;
}
}
long long ans = 0;
for(int i = 1; i <= k; i++){
ans += dp[i];
ans %= MOD;
}
cout << ans + 1 << endl;
}
详细
Test #1:
score: 100
Accepted
time: 149ms
memory: 18956kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 139ms
memory: 18908kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 139ms
memory: 18988kb
input:
10000 10000
output:
689223145
result:
ok single line: '689223145'
Test #4:
score: 0
Accepted
time: 154ms
memory: 19100kb
input:
9999 31
output:
986106162
result:
ok single line: '986106162'
Test #5:
score: 0
Accepted
time: 151ms
memory: 18964kb
input:
57 9817
output:
447253096
result:
ok single line: '447253096'
Test #6:
score: 0
Accepted
time: 138ms
memory: 18968kb
input:
501 499
output:
247755220
result:
ok single line: '247755220'
Test #7:
score: 0
Accepted
time: 156ms
memory: 18980kb
input:
97424 174829
output:
964884269
result:
ok single line: '964884269'
Test #8:
score: 0
Accepted
time: 145ms
memory: 19100kb
input:
11 13
output:
729153057
result:
ok single line: '729153057'
Test #9:
score: 0
Accepted
time: 147ms
memory: 18976kb
input:
200000 200000
output:
803771125
result:
ok single line: '803771125'
Test #10:
score: 0
Accepted
time: 142ms
memory: 19100kb
input:
199999 562
output:
865836540
result:
ok single line: '865836540'
Test #11:
score: 0
Accepted
time: 137ms
memory: 18988kb
input:
3539 189423
output:
530738158
result:
ok single line: '530738158'
Test #12:
score: 0
Accepted
time: 136ms
memory: 19100kb
input:
198324 173852
output:
963717515
result:
ok single line: '963717515'
Test #13:
score: 0
Accepted
time: 161ms
memory: 19100kb
input:
1 1
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 146ms
memory: 18976kb
input:
1000000 1000000
output:
800590912
result:
ok single line: '800590912'
Test #15:
score: 0
Accepted
time: 151ms
memory: 18976kb
input:
5034 999999
output:
946555033
result:
ok single line: '946555033'
Test #16:
score: 0
Accepted
time: 140ms
memory: 19100kb
input:
999998 2042
output:
713878368
result:
ok single line: '713878368'