結果

問題 No.1161 Many Powers
ユーザー 蜜蜂
提出日時 2020-08-11 19:56:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 75,588 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-09 11:39:24
合計ジャッジ時間 3,503 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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