QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136385#6417. Classical Summation Problemfeeder1#WA 23ms19264kbC++171.6kb2023-08-08 12:20:552023-08-08 12:20:56

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 12:20:56]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:19264kb
  • [2023-08-08 12:20:55]
  • 提交

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;

ll 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 (ll 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: 11ms
memory: 19088kb

input:

3 2

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 7ms
memory: 19264kb

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: 7ms
memory: 19092kb

input:

10 9

output:

508778235

result:

ok 1 number(s): "508778235"

Test #5:

score: 0
Accepted
time: 7ms
memory: 19264kb

input:

69 3

output:

11497815

result:

ok 1 number(s): "11497815"

Test #6:

score: 0
Accepted
time: 8ms
memory: 19148kb

input:

994 515

output:

33689623

result:

ok 1 number(s): "33689623"

Test #7:

score: 0
Accepted
time: 5ms
memory: 19040kb

input:

4476 6182

output:

114894183

result:

ok 1 number(s): "114894183"

Test #8:

score: 0
Accepted
time: 7ms
memory: 19040kb

input:

58957 12755

output:

932388891

result:

ok 1 number(s): "932388891"

Test #9:

score: -100
Wrong Answer
time: 23ms
memory: 19064kb

input:

218138 28238

output:

658450766

result:

wrong answer 1st numbers differ - expected: '392861201', found: '658450766'