結果

問題 No.16 累乗の加算
コンテスト
ユーザー mitsushino
提出日時 2018-01-11 11:13:03
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 92 ms / 5,000 ms
+ 693µs
コード長 607 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 309 ms
コンパイル使用メモリ 21,408 KB
実行使用メモリ 15,868 KB
最終ジャッジ日時 2026-07-30 08:24:43
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# -*- coding: utf-8 -*-
M = 1000003


def binary_exponent(x, exponent):
    sum_values = 1
    quotient = exponent
    square_num = x
    while quotient > 0:
        quotient, mod = divmod(quotient, 2)
        if mod == 1:
            sum_values *= square_num
        square_num = pow(square_num, 2) % M
    return sum_values


if __name__ == '__main__':
    xN = list(map(int, input().split()))
    x = xN[0]
    N = xN[1]
    exponent_list = list(map(int, input().split()))
    sum_values = 0
    for exponent in exponent_list:
        sum_values += binary_exponent(x, exponent)
    print(sum_values % M)
0