結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2015-06-09 00:08:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 682 bytes |
コンパイル時間 | 507 ms |
コンパイル使用メモリ | 60,028 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 04:56:03 |
合計ジャッジ時間 | 1,141 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
#include <iostream> #include <vector> using namespace std; const long long MOD = 1000003LL; long long powered[33] = { 1 }; long long power(int a) { long long result = 1LL; for (int i = 1; a > 0; ++i, a >>= 1) { if (a & 0x1) { result *= powered[i]; result %= MOD; } } return result; } int main() { long long x; int n; cin >> x >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } powered[1] = x; for (int i = 2; i <= 32; ++i) { powered[i] = powered[i - 1] * powered[i - 1]; powered[i] %= MOD; } long long result = 0LL; for (int i = 0; i < n; ++i) { result += power(a[i]); result %= MOD; } cout << result << endl; return 0; }