結果

問題 No.181 A↑↑N mod M
ユーザー Kiri8128Kiri8128
提出日時 2022-04-17 15:29:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,024 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 77,024 KB
最終ジャッジ日時 2023-08-27 02:47:58
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,308 KB
testcase_01 AC 70 ms
71,640 KB
testcase_02 AC 80 ms
76,408 KB
testcase_03 AC 73 ms
71,172 KB
testcase_04 AC 86 ms
76,748 KB
testcase_05 AC 86 ms
76,680 KB
testcase_06 AC 75 ms
70,972 KB
testcase_07 AC 74 ms
71,024 KB
testcase_08 AC 88 ms
76,864 KB
testcase_09 AC 87 ms
76,708 KB
testcase_10 AC 86 ms
77,024 KB
testcase_11 AC 88 ms
76,812 KB
testcase_12 AC 86 ms
76,960 KB
testcase_13 AC 87 ms
76,820 KB
testcase_14 AC 88 ms
76,828 KB
testcase_15 AC 86 ms
76,784 KB
testcase_16 AC 83 ms
76,760 KB
testcase_17 AC 84 ms
76,840 KB
testcase_18 AC 83 ms
76,784 KB
testcase_19 AC 83 ms
76,316 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 80 ms
76,340 KB
testcase_23 AC 79 ms
76,444 KB
testcase_24 AC 80 ms
76,688 KB
testcase_25 AC 82 ms
76,976 KB
testcase_26 AC 84 ms
76,816 KB
testcase_27 AC 73 ms
71,360 KB
testcase_28 AC 73 ms
71,364 KB
testcase_29 AC 73 ms
71,132 KB
testcase_30 AC 72 ms
71,556 KB
testcase_31 AC 74 ms
71,508 KB
testcase_32 AC 73 ms
71,024 KB
testcase_33 AC 84 ms
76,744 KB
testcase_34 AC 86 ms
76,692 KB
testcase_35 AC 86 ms
76,760 KB
testcase_36 AC 86 ms
76,836 KB
testcase_37 AC 84 ms
76,752 KB
testcase_38 AC 86 ms
76,768 KB
testcase_39 AC 85 ms
76,748 KB
testcase_40 AC 86 ms
76,764 KB
testcase_41 AC 88 ms
76,944 KB
testcase_42 AC 86 ms
76,748 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 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