結果

問題 No.16 累乗の加算
ユーザー youjo_yamiotiyoujo_yamioti
提出日時 2018-12-07 01:50:25
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 465 bytes
コンパイル時間 3,233 ms
コンパイル使用メモリ 143,712 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-12 03:25:34
合計ジャッジ時間 4,519 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int powModM(int, int)’:
main.cpp:7:37: warning: control reaches end of non-void function [-Wreturn-type]
     else (powModM(x,a-1) * (x % M)) % M;
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~

ソースコード

diff #

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