結果

問題 No.181 A↑↑N mod M
ユーザー Kiri8128Kiri8128
提出日時 2022-04-17 15:29:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 1,056 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 77,280 KB
最終ジャッジ日時 2023-08-27 02:48:25
合計ジャッジ時間 5,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,648 KB
testcase_01 AC 72 ms
71,492 KB
testcase_02 AC 82 ms
76,532 KB
testcase_03 AC 76 ms
70,996 KB
testcase_04 AC 84 ms
76,820 KB
testcase_05 AC 85 ms
76,960 KB
testcase_06 AC 72 ms
71,164 KB
testcase_07 AC 71 ms
71,212 KB
testcase_08 AC 84 ms
76,740 KB
testcase_09 AC 83 ms
77,092 KB
testcase_10 AC 86 ms
76,760 KB
testcase_11 AC 86 ms
76,832 KB
testcase_12 AC 83 ms
76,960 KB
testcase_13 AC 83 ms
76,684 KB
testcase_14 AC 84 ms
76,828 KB
testcase_15 AC 86 ms
76,664 KB
testcase_16 AC 87 ms
76,816 KB
testcase_17 AC 86 ms
76,816 KB
testcase_18 AC 87 ms
77,280 KB
testcase_19 AC 73 ms
70,856 KB
testcase_20 AC 74 ms
71,204 KB
testcase_21 AC 75 ms
70,928 KB
testcase_22 AC 74 ms
71,088 KB
testcase_23 AC 84 ms
76,332 KB
testcase_24 AC 84 ms
76,764 KB
testcase_25 AC 88 ms
77,008 KB
testcase_26 AC 85 ms
76,716 KB
testcase_27 AC 73 ms
71,580 KB
testcase_28 AC 74 ms
71,412 KB
testcase_29 AC 74 ms
71,056 KB
testcase_30 AC 75 ms
71,392 KB
testcase_31 AC 76 ms
71,340 KB
testcase_32 AC 75 ms
71,260 KB
testcase_33 AC 88 ms
76,692 KB
testcase_34 AC 88 ms
76,784 KB
testcase_35 AC 88 ms
76,792 KB
testcase_36 AC 87 ms
76,816 KB
testcase_37 AC 88 ms
76,784 KB
testcase_38 AC 87 ms
76,728 KB
testcase_39 AC 87 ms
76,860 KB
testcase_40 AC 87 ms
76,692 KB
testcase_41 AC 87 ms
76,940 KB
testcase_42 AC 87 ms
76,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primeFactor(N):
    i, n, ret, d, sq = 2, N, {}, 2, 99
    while i <= sq:
        k = 0
        while n % i == 0: n, k, ret[i] = n//i, k+1, k+1
        if k > 0 or i == 97: sq = int(n**(1/2)+0.5)
        if i < 4: i = i * 2 - 1
        else: i, d = i+d, d^6
    if n > 1: ret[n] = 1
    return ret

# Euler's Totient Function
def ETF(N):
    pf = primeFactor(N)
    a = 1
    for p in pf:
        a *= (p-1) * (p ** (pf[p] - 1))
    return a

def powtower(m, L):
    if m == 1:
        return 0
    if not L:
        return 1
    def subcalc(m, L):
        a = L[0]
        if len(L) == 1:
            return a
        s = subcalc(ETF(m), L[1:])
        if a == s == 0:
            return 1 # 0 の 0 乗はここで定義
        if a == 1:
            return 1
        if s <= 100:
            return a ** s
        # a > 1 かつ s > 100 なら a ** s は十分大きいので適当に小さくしてよい
        return pow(a, s, m) + m * 100
    return subcalc(m, L) % m

A, N, M = map(int, input().split())
print(powtower(M, [A] * min(N, 1000)))
0