QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#136384 | #6417. Classical Summation Problem | feeder1# | WA | 19ms | 19204kb | C++17 | 1.6kb | 2023-08-08 12:16:15 | 2023-08-08 12:16:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int, int, int> tii;
typedef tuple<ll, ll, ll> tll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e6 + 5;
const ll mod = 998244353;
int fpow(int b, int p) {
ll res = 1;
b %= mod;
while (p) {
if (p & 1) {
res = (ll) res * b % mod;
}
b = (ll) b * b % mod;
p >>= 1;
}
return res;
}
ll fac[maxn], ifac[maxn];
ll inv(ll a) {
return fpow(a, mod - 2);
}
ll ncr(ll a, ll b){
if (b > a) return 0;
return fac[a] * ifac[b] % mod * ifac[a-b] % mod;
}
void initfac(){
fac[0] = 1;
for (int i = 1; i < maxn; i++) fac[i] = fac[i-1] * i % mod;
ifac[maxn - 1] = inv(fac[maxn - 1]);
for (int i = maxn - 1; i >= 1; i--) ifac[i - 1] = ifac[i] * i % mod;
}
ll n, m, q, k, t, a, b, c;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
initfac();
cin >> n >> k;
if (k % 2) {
cout << fpow(n, k) * inv(2) % mod * (n + 1) % mod;
} else {
ll ans = fpow(n, k) * (n + 1) % mod;
ll nck = ncr(k, k / 2);
k = k / 2;
for (int i = 1; i <= n - 1; i++) {
ans = (ans - nck * fpow(i * (n - i), k)) % mod;
}
ans = (ans + mod) * inv(2) % mod;
cout << ans;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 12ms
memory: 19156kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 11ms
memory: 19172kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 11ms
memory: 19112kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 6ms
memory: 19204kb
input:
10 9
output:
508778235
result:
ok 1 number(s): "508778235"
Test #5:
score: 0
Accepted
time: 8ms
memory: 19116kb
input:
69 3
output:
11497815
result:
ok 1 number(s): "11497815"
Test #6:
score: 0
Accepted
time: 8ms
memory: 19176kb
input:
994 515
output:
33689623
result:
ok 1 number(s): "33689623"
Test #7:
score: 0
Accepted
time: 3ms
memory: 19152kb
input:
4476 6182
output:
114894183
result:
ok 1 number(s): "114894183"
Test #8:
score: 0
Accepted
time: 12ms
memory: 19156kb
input:
58957 12755
output:
932388891
result:
ok 1 number(s): "932388891"
Test #9:
score: -100
Wrong Answer
time: 19ms
memory: 19100kb
input:
218138 28238
output:
658450766
result:
wrong answer 1st numbers differ - expected: '392861201', found: '658450766'