結果

問題 No.16 累乗の加算
ユーザー maatanbetamaatanbeta
提出日時 2017-04-28 16:49:06
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
実行時間 -
コード長 835 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-10-11 18:55:10
合計ジャッジ時間 1,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,396 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 17 ms
8,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import log10
# import sys
# sys.setrecursionlimit(100000)
x, N = map(int, input().split())
a = list(map(int, input().split()))
xp = 0
n = 1000003
j = 0


def keta(x, a):
    ketasuu = int(a * log10(x)) + 1
    return ketasuu


def amari(x, a, n):
    if keta(x, a) <= 14:
        return (x ** a) % n
    else:
        makexp(x, n)
        result = 0
        r = a // xp
        result = (x ** (a % xp)) * amari(j, r, n)
        result = result % n
        return result


def makexp(x, n):
    global xp
    global j
    if x > 1:
        i = 0
        while(True):
            if x ** i > n:
                xp = i
                j = x ** i - n
                return None
                break
            i += 1


shiguma = 0
for i in range(N):
    shiguma += amari(x, a[i], n)
    shiguma = shiguma % n

print(shiguma)
0