結果

問題 No.1161 Many Powers
ユーザー t98slidert98slider
提出日時 2022-12-18 23:24:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,037 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 165,264 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 09:16:20
合計ジャッジ時間 3,124 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 25 ms
4,376 KB
testcase_09 AC 27 ms
4,380 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 32 ms
4,380 KB
testcase_14 AC 49 ms
4,380 KB
testcase_15 AC 42 ms
4,380 KB
testcase_16 AC 55 ms
4,380 KB
testcase_17 AC 36 ms
4,376 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 16 ms
4,380 KB
testcase_20 AC 57 ms
4,384 KB
testcase_21 AC 15 ms
4,376 KB
testcase_22 AC 59 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct barrett {
    unsigned int _m;
    unsigned long long im;
    explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
    unsigned int umod() const { return _m; }
    unsigned int mul(unsigned int a, unsigned int b) const {
        unsigned long long z = a;
        z *= b;
        unsigned int v = (unsigned int)(z % _m);
        return v;
    }
};

long long pow_mod(long long x, long long n, int m) {
    assert(0 <= n && 1 <= m);
    if (m == 1) return 0;
    barrett bt(m);
    unsigned int r = 1, y = (unsigned int)(x % m);
    while (n) {
        if (n & 1) r = bt.mul(r, y);
        y = bt.mul(y, y);
        n >>= 1;
    }
    return r;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A, B, C;
    cin >> A >> B >> C;
    ll ans = 0;
    for(int i = 1, rem = A % C; i < C; i++){
        ll d = A / C;
        if(i <= rem) d++;
        (ans += d * pow_mod(i, B, C)) %= C;
    }
    cout << ans << '\n';
}
0