結果

問題 No.1897 Sum of 2nd Max
ユーザー ぷらぷら
提出日時 2022-04-08 21:34:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 199,864 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 00:14:24
合計ジャッジ時間 4,149 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 72 ms
4,380 KB
testcase_04 AC 72 ms
4,376 KB
testcase_05 AC 35 ms
4,376 KB
testcase_06 AC 37 ms
4,376 KB
testcase_07 AC 49 ms
4,376 KB
testcase_08 AC 38 ms
4,380 KB
testcase_09 AC 74 ms
4,376 KB
testcase_10 AC 70 ms
4,376 KB
testcase_11 AC 71 ms
4,376 KB
testcase_12 AC 71 ms
4,380 KB
testcase_13 AC 74 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 23 ms
4,376 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 21 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 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 74 ms
4,380 KB
testcase_31 AC 72 ms
4,376 KB
testcase_32 AC 49 ms
4,376 KB
testcase_33 AC 75 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

int main() {
    int N,K;
    cin >> N >> K;
    int ans = 0;
    for(int i = 1; i <= K; i++) {
        ans += 1ll*(K-i)*N%mod*i%mod*(modpow(i,N-1)+mod-modpow(i-1,N-1))%mod;
        ans %= mod;
        ans += 1ll*i*((modpow(i,N)+mod-modpow(i-1,N))%mod+mod-1ll*N*modpow(i-1,N-1)%mod)%mod;
        ans %= mod;
    }
    cout << ans << endl;
}
0