結果

問題 No.16 累乗の加算
ユーザー Knots_coderKnots_coder
提出日時 2022-03-26 18:03:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,531 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 97,572 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 10:04:06
合計ジャッジ時間 1,376 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <bitset>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <functional>
#include <stack>
#include <cmath>
#include <string>
#include <complex>
#include <cassert>
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = (1<<30)-1;
//const int MOD = 1e9+7;
const int MOD = 1000003;
const ll LINF = (1ll<<62)-1;

#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"
#define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n";

/**
 *繰り返し二乗法
 *時間計算量:O(logn)
 *空間計算量:O(1)
**/
long long powpow(long long x,long long n){///通常のpow
    long long ret = 1;
    while(n>0){
        if(n&1)ret *= x;
        x *= x;
        n >>= 1; //nを1bit右にずらす
    }
    return ret;
}

long long powmod(long long x,long long n){//MODを取る時
    long long ret = 1;
    while(n>0){
        if(n&1)ret = ret * x % MOD;
        x = x*x % MOD;
        n >>= 1; //nを1bit右にずらす
    }
    return ret;
}

int main(){
    ll x,n,a;cin >> x >> n;
    ll ans = 0;
    REP(i,n){
        cin >> a;
        ans += powmod(x,a);
        ans %= MOD;
    }
    COUT(ans);
}




















0