結果

問題 No.1897 Sum of 2nd Max
ユーザー 👑 ygussanyygussany
提出日時 2022-03-20 10:43:48
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 31,232 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 06:44:38
合計ジャッジ時間 2,731 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 73 ms
5,376 KB
testcase_04 AC 71 ms
5,376 KB
testcase_05 AC 35 ms
5,376 KB
testcase_06 AC 37 ms
5,376 KB
testcase_07 AC 48 ms
5,376 KB
testcase_08 AC 37 ms
5,376 KB
testcase_09 AC 74 ms
5,376 KB
testcase_10 AC 75 ms
5,376 KB
testcase_11 AC 74 ms
5,376 KB
testcase_12 AC 76 ms
5,376 KB
testcase_13 AC 74 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 23 ms
5,376 KB
testcase_17 AC 18 ms
5,376 KB
testcase_18 AC 20 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 77 ms
5,376 KB
testcase_31 AC 77 ms
5,376 KB
testcase_32 AC 51 ms
5,376 KB
testcase_33 AC 78 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 998244353;

long long pow_mod(int n, long long k)
{
	long long N, ans = 1;
	for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod;
	return ans;
}

int main()
{
	int N, K;
	scanf("%d %d", &N, &K);
	
	int i;
	long long ans = 1 + (long long)N * (K - 1) % Mod, tmp;
	for (i = 2; i <= K; i++) {
		tmp = 0;
		if (i < K) tmp += (pow_mod(i, N - 1) - pow_mod(i - 1, N - 1) + Mod) * (K - i) % Mod * N % Mod;
		tmp += pow_mod(i, N) - pow_mod(i - 1, N) + Mod - pow_mod(i - 1, N - 1) * N % Mod + Mod;
		ans += tmp * i % Mod;
	}
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0