結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,336 KB
testcase_01 AC 19 ms
8,944 KB
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,536 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