結果
問題 |
No.16 累乗の加算
|
ユーザー |
![]() |
提出日時 | 2016-10-06 15:38:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 828 bytes |
コンパイル時間 | 645 ms |
コンパイル使用メモリ | 63,744 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 05:16:58 |
合計ジャッジ時間 | 1,276 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
#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; }