結果

問題 No.16 累乗の加算
コンテスト
ユーザー b1ue
提出日時 2018-04-13 22:47:46
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 110 ms / 5,000 ms
コード長 483 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 335 ms
コンパイル使用メモリ 20,440 KB
実行使用メモリ 15,236 KB
最終ジャッジ日時 2026-03-13 18:40:52
合計ジャッジ時間 2,568 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:10: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  if y is 0:

ソースコード

diff #
raw source code

def exps_input(exps):
    return [int(e) for e in exps.split(' ')]


mod = 1_000_003


def pow_2(x, y):
    K = 1
    if y is 0:
        return 1
    while y > 1:
        if y % 2 == 0:
            x = x ** 2 % mod
            y = y // 2
        else:
            K = K * x % mod
            x = x ** 2 % mod
            y = (y - 1) // 2
    return K * x % mod


sum = 0
base = int(input().split(' ')[0])
for exp in exps_input(input()):
    sum += pow_2(base, exp)

print(sum % mod)
0