結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-27 20:36:00 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 645 bytes |
| コンパイル時間 | 883 ms |
| コンパイル使用メモリ | 105,780 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 03:46:42 |
| 合計ジャッジ時間 | 1,232 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv, std.math;
import std.stdio, std.typecons;
const long mod = 1000003;
void main()
{
auto rd = readln.split.map!(to!long);
auto x = rd[0];
auto n = rd[1];
auto ai = readln.split.map!(to!long).array;
auto pow_table = [x];
writeln(ai.map!(a => pow(x, a, pow_table)).sum % mod);
}
long pow(long x, long n, long[] pow_table)
{
auto c = 1;
for (auto r = 1; n > 0; (r += 1, n >>= 1)) {
if (pow_table.length < r)
pow_table ~= (pow_table.back ^^ 2) % mod;
if ((n & 1) == 1)
c = (c * pow_table[r - 1]) % mod;
}
return c;
}