結果

問題 No.2351 Butterfly in Summer
ユーザー inkyamaninkyaman
提出日時 2024-03-30 20:31:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 115,740 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-30 20:31:45
合計ジャッジ時間 2,586 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
#include <tuple>
using namespace std;
using ll = long long;

ll N, K;
ll mod = 998244353;

//ループの回数は適宜修正
ll power(ll a, ll b, ll m) {
    ll p = a, ans = 1;
    for(int i = 0; i < 60; i++) {
        ll wari = (1LL << i);
        if((b / wari) % 2 == 1) {
            ans = (ans * p) % m;
        }
        p = (p * p) % m;
    }
    return ans;
}

/*
フェルマーの小定理を利用して、徐算a/bの答えを素数Mで割ったあまりを算出
a,bはllとしているが、m以上の場合はそれぞれa%m,b%mで渡す
*/

ll division(ll a, ll b, ll m) {
    return ((a % m) * power(b, m-2, m)) % m;
}

int main() {

    cin >> N >> K;
    ll b = division(1, power(K,N,mod), mod);
    ll a = N*K*(K-1)%mod;
    cout << (a*b)%mod << endl;
    
}

0