結果

問題 No.181 A↑↑N mod M
ユーザー Kiri8128Kiri8128
提出日時 2022-04-17 15:26:27
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 982 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 836,120 KB
最終ジャッジ日時 2023-08-27 02:47:07
合計ジャッジ時間 5,644 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,532 KB
testcase_01 AC 66 ms
71,664 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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):
    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] * N))
0