結果

問題 No.16 累乗の加算
ユーザー woodsgreenwoodsgreen
提出日時 2022-01-11 01:55:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 562 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 193,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 20:29:08
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int M=1000003;
long long pw[40]={1};
long long x,n,a,ans;
long long pw_md(long long p){
    long long res=1,cnt=0;
    while(p){
        if(p%2){
            res*=pw[cnt+1];
            res%=M;
        }
        ++cnt;
        p/=2;
    }
    return res;
}
int main(){
    cin>>x>>n;
    pw[1]=x;
    for(int i=2;i<40;++i)
        pw[i]=pw[i-1]*pw[i-1]%M;
    for(int i=0;i<n;++i){
        cin>>a;
        ans+=pw_md(a);
        ans%=M;
    }
    cout<<ans<<endl;
    return 0;
}
0