結果

問題 No.16 累乗の加算
ユーザー KuphonyKuphony
提出日時 2016-03-17 22:10:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 67,608 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:56:45
合計ジャッジ時間 1,714 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
using namespace std;

long long mod = 1000003;
//二分累乗法
long long pow(long long x,long long n){
    long long c = 0;
    if (n == 0) {return 1;}
    if (n == 1){ return x;}
    //漸化式
    if(n%2 == 1){
        return x * pow(x,n - 1) % mod;
    }
    else{
        long long c = pow(x,n/2);
        return c * c % mod;
    }
}

int main(int argc, const char * argv[]) {
    long long x;
    cin >> x;
    long long N;
    cin >> N;
    long long n;
    long long result = 0;
    vector<long long>a;
    for (int i = 0; i < N; i++) {
        cin >> n;
        result += pow(x,n);
    }
    cout << result%mod;
    cout << "\n";
}
0