結果

問題 No.16 累乗の加算
ユーザー ronpooronpoo
提出日時 2023-08-22 17:38:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 373 bytes
コンパイル時間 970 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 75,916 KB
最終ジャッジ日時 2023-08-22 17:38:25
合計ジャッジ時間 2,227 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,356 KB
testcase_01 AC 68 ms
71,472 KB
testcase_02 AC 74 ms
75,864 KB
testcase_03 AC 70 ms
71,388 KB
testcase_04 AC 69 ms
71,376 KB
testcase_05 AC 69 ms
71,472 KB
testcase_06 AC 74 ms
75,848 KB
testcase_07 AC 73 ms
75,816 KB
testcase_08 AC 80 ms
75,656 KB
testcase_09 AC 74 ms
75,648 KB
testcase_10 AC 73 ms
75,800 KB
testcase_11 AC 69 ms
71,276 KB
testcase_12 AC 73 ms
75,916 KB
testcase_13 AC 70 ms
71,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

x, N = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10**6 + 3

def power(a, b):
    d = len(format(b, 'b'))
    ret = 1
    n = a
    for i in range(d):
        if b & (1 << i) > 0:
            ret *= n
            ret %= MOD
        n = (n**2) % MOD
    return ret

ans = 0
for i in range(N):
    ans += power(x, a[i])
    ans %= MOD
    
print(ans)
0