結果

問題 No.181 A↑↑N mod M
ユーザー maspymaspy
提出日時 2020-04-10 12:46:03
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 144 ms / 5,000 ms
コード長 595 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 29,872 KB
最終ジャッジ日時 2023-10-13 00:17:32
合計ジャッジ時間 8,190 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
29,716 KB
testcase_01 AC 140 ms
29,740 KB
testcase_02 AC 144 ms
29,864 KB
testcase_03 AC 138 ms
29,860 KB
testcase_04 AC 136 ms
29,820 KB
testcase_05 AC 138 ms
29,732 KB
testcase_06 AC 139 ms
29,784 KB
testcase_07 AC 142 ms
29,824 KB
testcase_08 AC 139 ms
29,784 KB
testcase_09 AC 138 ms
29,860 KB
testcase_10 AC 138 ms
29,864 KB
testcase_11 AC 139 ms
29,656 KB
testcase_12 AC 141 ms
29,700 KB
testcase_13 AC 137 ms
29,740 KB
testcase_14 AC 138 ms
29,664 KB
testcase_15 AC 140 ms
29,740 KB
testcase_16 AC 139 ms
29,796 KB
testcase_17 AC 138 ms
29,768 KB
testcase_18 AC 139 ms
29,796 KB
testcase_19 AC 138 ms
29,752 KB
testcase_20 AC 139 ms
29,692 KB
testcase_21 AC 138 ms
29,688 KB
testcase_22 AC 137 ms
29,784 KB
testcase_23 AC 137 ms
29,764 KB
testcase_24 AC 140 ms
29,724 KB
testcase_25 AC 141 ms
29,736 KB
testcase_26 AC 139 ms
29,832 KB
testcase_27 AC 140 ms
29,852 KB
testcase_28 AC 139 ms
29,812 KB
testcase_29 AC 138 ms
29,800 KB
testcase_30 AC 138 ms
29,652 KB
testcase_31 AC 142 ms
29,788 KB
testcase_32 AC 140 ms
29,724 KB
testcase_33 AC 140 ms
29,872 KB
testcase_34 AC 140 ms
29,716 KB
testcase_35 AC 140 ms
29,744 KB
testcase_36 AC 139 ms
29,804 KB
testcase_37 AC 140 ms
29,716 KB
testcase_38 AC 140 ms
29,820 KB
testcase_39 AC 140 ms
29,712 KB
testcase_40 AC 139 ms
29,708 KB
testcase_41 AC 140 ms
29,724 KB
testcase_42 AC 140 ms
29,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

U = int(10 ** 4)
phi = np.arange(U)
for p in range(2, U):
    if phi[p] == p:
        phi[::p] -= phi[::p] // p


def f(A, N, M):
    if A == 1:
        return 1
    if N == 0:
        return 1
    if M == 1:
        return 1
    MM = int(phi[M])
    x = f(A, N - 1, MM)
    if x >= MM or x >= 20:
        return M + pow(A, x, M)
    x = A ** x
    if x >= M:
        return (x % M) + M
    return x


A, N, M = map(int, read().split())
print(f(A, N, M) % M)
0