結果

問題 No.16 累乗の加算
ユーザー rpy3cpprpy3cpp
提出日時 2015-08-06 00:02:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2023-09-08 11:43:32
合計ジャッジ時間 1,050 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,880 KB
testcase_01 AC 16 ms
7,840 KB
testcase_02 AC 16 ms
7,908 KB
testcase_03 AC 16 ms
7,792 KB
testcase_04 AC 16 ms
7,780 KB
testcase_05 AC 15 ms
7,948 KB
testcase_06 AC 15 ms
7,780 KB
testcase_07 AC 15 ms
7,784 KB
testcase_08 AC 16 ms
7,860 KB
testcase_09 AC 16 ms
7,788 KB
testcase_10 AC 16 ms
7,796 KB
testcase_11 AC 15 ms
7,908 KB
testcase_12 AC 15 ms
7,952 KB
testcase_13 AC 16 ms
7,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

x, N = map(int, input().split())
As = list(map(int, input().split()))

def solve(x, N, As):
    mod = 10**6 + 3
    dp = [1]
    maxA = max(As)
    val = x
    while maxA:
        dp.append(val)
        val *= val
        val %= mod
        maxA >>= 1
    ans = 0
    for a in As:
        val = 1
        i = 0
        while a:
            i += 1
            if a & 1:
                val *= dp[i]
                val %= mod
            a >>= 1
        ans += val
    return ans % mod

print(solve(x, N, As))
0