結果

問題 No.1161 Many Powers
ユーザー 蜜蜂蜜蜂
提出日時 2020-08-11 19:56:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 75,896 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 17:32:22
合計ジャッジ時間 2,774 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 7 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 82 ms
5,376 KB
testcase_09 AC 100 ms
5,376 KB
testcase_10 AC 36 ms
5,376 KB
testcase_11 AC 69 ms
5,376 KB
testcase_12 AC 35 ms
5,376 KB
testcase_13 AC 104 ms
5,376 KB
testcase_14 AC 186 ms
5,376 KB
testcase_15 AC 136 ms
5,376 KB
testcase_16 AC 161 ms
5,376 KB
testcase_17 AC 116 ms
5,376 KB
testcase_18 AC 99 ms
5,376 KB
testcase_19 AC 58 ms
5,376 KB
testcase_20 AC 217 ms
5,376 KB
testcase_21 AC 35 ms
5,376 KB
testcase_22 AC 145 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}

int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=0;
    ll mod=0;
    for(ll i=0;i<=c;i++){
        mod+=mpower(i,b,c);
        mod%=c;
    }
    ans+=mod*(a/c);
    ans%=c;
    for(ll i=0;i<=a%c;i++){
        ans+=mpower(i,b,c);
        ans%=c;
    }
    cout<<ans;
    return 0;
}
0