結果

問題 No.16 累乗の加算
ユーザー kutsutama
提出日時 2018-03-11 10:40:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 608 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-26 05:26:38
合計ジャッジ時間 1,452 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

x, n = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
mod = 10**6 + 3

def powmod(ai, mod, memo):
    if ai in memo:
        return memo[ai]
    res = 0
    if ai == 0:
        res = 1
    elif ai % 2 == 0:
        res = powmod(ai // 2, mod, memo) * powmod(ai // 2, mod, memo) % mod
    else:
        res = (x * powmod((ai - 1) // 2, mod, memo)
                * powmod((ai - 1) // 2, mod, memo) % mod)
    if len(memo) < 10000000:
        memo[ai] = res
    return res

memo = {}
res = 0
for ai in a:
    res = (res + powmod(ai, mod, memo)) % mod
print(res)
0