結果

問題 No.1897 Sum of 2nd Max
ユーザー FF256grhy
提出日時 2022-04-09 00:41:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 425 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 67,272 KB
最終ジャッジ日時 2025-01-28 16:51:01
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
using LL = long long int;
const LL M = 998244353;
LL ex(LL a, LL b) {
	LL ans = 1, e = a;
	while(b) {
		if(b & 1) { (ans *= e) %= M; }
		(e *= e) %= M;
		b >>= 1;
	}
	return ans;
}
int main() {
	LL n, k; cin >> n >> k;
	LL ans = ex(k, n + 1);
	for(LL i = 1; i <= k - 1; i++) {
		(ans -= (k * n - i * (n - 1)) % M * ex(i, n - 1)) %= M;
	}
	ans = (ans + M) % M;
	cout << ans << endl;
}
0