QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#409426 | #3161. Another Coin Weighing Puzzle | ucup-team1716# | AC ✓ | 298ms | 10976kb | C++20 | 929b | 2024-05-12 03:22:06 | 2024-05-12 03:22:07 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll N = 998244353;
//Modded Power
ll mpow(ll a, ll n)
{
if(n==0) return 1;
ll x = mpow(a, n/2);
x = (x*x)%N;
if(n%2==0) return x;
else return (x*a)%N;
}
//Inverse
ll inv(ll a)
{
return mpow(a, N-2);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, k;
cin >> k >> n;
vector<ll> ans(n+1, 0);
ans[0] = 1;
for(int i=1; i<=n; i++)
{
ans[i] += mpow(2 * i + 1, k) - mpow(2 * i - 1, k);
ans[i] += ans[i-1];
for(int j=2*i; j<=n; j+=i)
{
ans[j] -= ans[i] - ans[i-1];
ans[j] %= N;
}
ans[i] = ans[i] % N;
if(ans[i] < 0) ans[i] += N;
}
/*for(ll x: ans) cout << x << " ";
cout << "\n";*/
cout << ans[n];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3444kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
10000 10000
output:
689223145
result:
ok single line: '689223145'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
9999 31
output:
986106162
result:
ok single line: '986106162'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3644kb
input:
57 9817
output:
447253096
result:
ok single line: '447253096'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
501 499
output:
247755220
result:
ok single line: '247755220'
Test #7:
score: 0
Accepted
time: 47ms
memory: 4428kb
input:
97424 174829
output:
964884269
result:
ok single line: '964884269'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
11 13
output:
729153057
result:
ok single line: '729153057'
Test #9:
score: 0
Accepted
time: 52ms
memory: 4684kb
input:
200000 200000
output:
803771125
result:
ok single line: '803771125'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3748kb
input:
199999 562
output:
865836540
result:
ok single line: '865836540'
Test #11:
score: 0
Accepted
time: 38ms
memory: 4732kb
input:
3539 189423
output:
530738158
result:
ok single line: '530738158'
Test #12:
score: 0
Accepted
time: 59ms
memory: 4324kb
input:
198324 173852
output:
963717515
result:
ok single line: '963717515'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
1 1
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 298ms
memory: 10852kb
input:
1000000 1000000
output:
800590912
result:
ok single line: '800590912'
Test #15:
score: 0
Accepted
time: 203ms
memory: 10976kb
input:
5034 999999
output:
946555033
result:
ok single line: '946555033'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
999998 2042
output:
713878368
result:
ok single line: '713878368'