結果

問題 No.1161 Many Powers
ユーザー Sooh31
提出日時 2020-08-18 22:25:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 191,696 KB
最終ジャッジ日時 2025-01-13 03:30:41
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const ll mod = 1000000007;
const int INF = 1001001001;

ll modpow(ll a, ll p, ll mod){
    ll res = 1;
    while(p){
        if(p & 1) res = res * a % mod;
        a = a * a % mod;
        p >>= 1;
    }
    return res;
}

int main(){
    ll a, b; cin >> a >> b;
    ll c; cin >> c;
    ll cnt = a / c;
    ll res = a % c;
    ll ans = 0;
    for(int i = 1; i <= c; i++){
        if(i <= res) ans += modpow(i, b, c) * (cnt + 1);
        else ans += modpow(i, b, c) * cnt;
        ans %= c;
    }
    cout << ans << endl;
}
0