結果

問題 No.16 累乗の加算
ユーザー youjo_yamiotiyoujo_yamioti
提出日時 2018-12-07 02:10:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 144,096 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 03:27:54
合計ジャッジ時間 2,104 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,356 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int M = 1000003;
long long int powModM(long long int x,long long int a){
    if(a == 0){
        return 1;
    }else if(a % 2 == 0){
        long long int t = powModM(x,a/2);
        return (t * t) % M;
    }else{
        return (powModM(x,a-1) * (x % M)) % M;
    }
}
int main(){
    long long int sum = 0;
    long long int ans;
    long long int x,N;
    cin >> x >> N;
    long long int a;
    for(int i=0;i<N;i++){
        cin >> a;
        sum += powModM(x,a);
    }
    ans = sum % M;
    cout << ans <<endl;
    return 0;
}
0