結果

問題 No.1897 Sum of 2nd Max
ユーザー publflpublfl
提出日時 2022-04-08 22:45:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 33,268 KB
実行使用メモリ 4,632 KB
最終ジャッジ日時 2023-08-19 01:13:43
合計ジャッジ時間 2,440 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 59 ms
4,536 KB
testcase_04 AC 56 ms
4,516 KB
testcase_05 AC 28 ms
4,376 KB
testcase_06 AC 30 ms
4,380 KB
testcase_07 AC 39 ms
4,380 KB
testcase_08 AC 30 ms
4,380 KB
testcase_09 AC 62 ms
4,604 KB
testcase_10 AC 57 ms
4,516 KB
testcase_11 AC 59 ms
4,512 KB
testcase_12 AC 58 ms
4,632 KB
testcase_13 AC 58 ms
4,584 KB
testcase_14 AC 14 ms
4,552 KB
testcase_15 AC 16 ms
4,464 KB
testcase_16 AC 22 ms
4,592 KB
testcase_17 AC 18 ms
4,564 KB
testcase_18 AC 20 ms
4,580 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 58 ms
4,544 KB
testcase_31 AC 60 ms
4,560 KB
testcase_32 AC 39 ms
4,380 KB
testcase_33 AC 59 ms
4,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#define MOD 998244353

long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int k = a;
	while(b)
	{
		if(b%2==1) ans*=k, ans %=MOD;
		b/=2;
		k*=k, k%=MOD;
	}
	return ans;
}

long long int count[200010];
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	
	long long int ans = 0;
	for(int i=1;i<=b;i++)
	{
		long long int val = power(i,a);
		val -= a*power(i-1,a-1), val %= MOD, val += MOD, val %= MOD;
		val -= power(i-1,a), val %= MOD, val += MOD, val %= MOD;
		val *= i, val %= MOD;
		ans += val, ans %= MOD;
	}
	
	for(int i=1;i<=b;i++) count[i] = power(i,a-1);
	for(int i=b;i>=1;i--) count[i] = (count[i]-count[i-1]+MOD)%MOD;
	
	long long int S = 0;
	for(int i=1;i<=b;i++)
	{
		S += (i-1)*count[i-1];
		S %= MOD;
		long long int val = S*a;
		val %= MOD;
		ans += val, ans %= MOD;
	}
	printf("%lld",ans);
}
0