QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#132481 | #6417. Classical Summation Problem | UFRJ# | WA | 12ms | 19256kb | C++20 | 1.2kb | 2023-07-30 00:16:02 | 2023-07-30 00:16:03 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using lint = int64_t;
const int mod = 998244353;
const int lim = 1e6 + 10;
lint power(lint x, lint n){
x %= mod;
lint res = 1;
for(;n;n>>=1){
if(n&1) res = res * x % mod;
x = x * x % mod;
}
return res;
}
lint fac[lim], ifac[lim];
void prep(){
fac[0] = 1;
for(int i=1;i<lim;i++) fac[i] = (fac[i-1] * i) % mod;
ifac[lim-1] = power(fac[lim-1], mod - 2);
for(int i=lim-2;i>=0;i--) ifac[i] = (ifac[i+1] * (i + 1)) % mod;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
prep();
lint n, k;
cin>>n>>k;
lint ans = power(n, k) * (n + 1) % mod * power(2, mod - 2) % mod;
if(k&1){
cout<<ans<<"\n";
}
else{
lint cnt = 0;
for(int i=1;i<=n;i++){
lint cur = (n + 1 - 2 * i + mod) % mod * (n + 1 - i) % mod * (power(i, k/2) - power(i - 1, k/2) + mod) % mod;
cnt = (cnt + cur) % mod;
}
cnt = cnt * fac[k] % mod * ifac[k/2] % mod * ifac[k/2] % mod * power(2, mod - 2) % mod;
ans = (ans - cnt + mod) % mod;
cout<<ans<<"\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 8ms
memory: 19044kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 12ms
memory: 19092kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 8ms
memory: 19104kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 11ms
memory: 19096kb
input:
10 9
output:
508778235
result:
ok 1 number(s): "508778235"
Test #5:
score: 0
Accepted
time: 11ms
memory: 19092kb
input:
69 3
output:
11497815
result:
ok 1 number(s): "11497815"
Test #6:
score: 0
Accepted
time: 11ms
memory: 19256kb
input:
994 515
output:
33689623
result:
ok 1 number(s): "33689623"
Test #7:
score: -100
Wrong Answer
time: 6ms
memory: 19104kb
input:
4476 6182
output:
344246384
result:
wrong answer 1st numbers differ - expected: '114894183', found: '344246384'