結果

問題 No.16 累乗の加算
ユーザー rpy3cpp
提出日時 2015-08-06 00:02:55
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-26 04:59:40
合計ジャッジ時間 1,296 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

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