結果

問題 No.16 累乗の加算
ユーザー maatanbetamaatanbeta
提出日時 2017-04-28 16:53:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 835 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 823,520 KB
最終ジャッジ日時 2023-10-11 18:57:18
合計ジャッジ時間 5,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from math import log10
import sys
sys.setrecursionlimit(1000000000)
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) <= 20:
        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