結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,508 KB
testcase_01 AC 67 ms
71,828 KB
testcase_02 AC 80 ms
76,672 KB
testcase_03 RE -
testcase_04 AC 81 ms
76,852 KB
testcase_05 AC 75 ms
77,200 KB
testcase_06 AC 71 ms
71,440 KB
testcase_07 AC 70 ms
71,140 KB
testcase_08 AC 75 ms
76,804 KB
testcase_09 AC 78 ms
76,708 KB
testcase_10 AC 75 ms
77,260 KB
testcase_11 AC 75 ms
76,936 KB
testcase_12 AC 77 ms
77,216 KB
testcase_13 AC 81 ms
76,720 KB
testcase_14 AC 89 ms
76,996 KB
testcase_15 AC 78 ms
77,276 KB
testcase_16 AC 78 ms
76,852 KB
testcase_17 AC 79 ms
76,984 KB
testcase_18 AC 78 ms
77,000 KB
testcase_19 AC 75 ms
76,628 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 77 ms
76,668 KB
testcase_23 AC 77 ms
76,488 KB
testcase_24 AC 75 ms
77,124 KB
testcase_25 AC 78 ms
77,584 KB
testcase_26 AC 75 ms
77,000 KB
testcase_27 AC 68 ms
71,612 KB
testcase_28 AC 67 ms
71,652 KB
testcase_29 AC 63 ms
71,584 KB
testcase_30 AC 65 ms
71,976 KB
testcase_31 AC 67 ms
71,448 KB
testcase_32 AC 65 ms
71,224 KB
testcase_33 AC 77 ms
76,984 KB
testcase_34 AC 78 ms
77,276 KB
testcase_35 AC 79 ms
77,088 KB
testcase_36 AC 77 ms
77,156 KB
testcase_37 AC 78 ms
76,720 KB
testcase_38 AC 80 ms
76,976 KB
testcase_39 AC 75 ms
77,180 KB
testcase_40 AC 76 ms
77,052 KB
testcase_41 AC 77 ms
76,836 KB
testcase_42 AC 77 ms
77,204 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):
    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