結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
vrjfsyi
|
| 提出日時 | 2018-03-25 10:35:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 824 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 73,980 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 05:27:17 |
| 合計ジャッジ時間 | 1,228 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <array>
#include <map>
#include <stack>
#include <queue>
#include <set>
using namespace std;
long pow(long x, long n, long m) {
long ans = 1;
while (n > 0) {
if ((n & 1) == 1) {
ans = (ans * x) % m;
}
x = x * x % m;
n = n >> 1;
}
return ans % m;
}
int main() {
int x, N;
cin >> x >> N;
map<long, long> m;
long modulo = 1000003;
long a;
long result = 0;
for (int j = 0; j < N; ++j) {
cin >> a;
if (m.find(a) != m.end()) {
result += m[a];
} else {
long b = pow(x, a, modulo);
result += b;
m[a] = b;
}
}
cout << (result % modulo) << "\n";
return 0;
}
vrjfsyi