結果

問題 No.16 累乗の加算
ユーザー Yang33Yang33
提出日時 2016-10-06 15:38:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 63,932 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 12:02:00
合計ジャッジ時間 1,421 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>


using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(int (i)=(s);(i)>(e);(i)--)
#define MOD 1000003

typedef long long llong;

/*
typedef vector<int> VI
typedef vector<double> VD
typedef vector<string> VS
typedef 
*/

/* 2進数で操作し、 1が立つところのみx^(n(2)bit部)を取り出す*/
llong powmod(llong x, int n, int mod) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) {
            res =(res*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int x, N;
    llong ans=0;
    cin >> x >> N;

    FOR(i, 0, N) {
        int a;
        cin >> a;
        ans += powmod(x, a, MOD);
    }
    cout << ans%MOD << endl;

    return 0;
}
0