結果

問題 No.181 A↑↑N mod M
ユーザー vwxyzvwxyz
提出日時 2023-12-08 04:15:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 937 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-12-08 04:15:58
合計ジャッジ時間 2,986 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
readline=sys.stdin.readline
from collections import defaultdict

def Factorize(N):
    assert N>=1
    factors=defaultdict(int)
    for p in range(2,N):
        if p**2>N:
            break
        while N%p==0:
            factors[p]+=1
            N//=p
    if N!=1:
        factors[N]+=1
    return factors

def Permutation_Product(x,n,f):
    lst=[]
    dct={}
    idx=0
    cur=x
    while True:
        if cur in dct.keys():
            loop_begin=dct[cur]
            loop_end=idx
            break
        else:
            lst.append(cur)
            dct[cur]=idx
            cur=f(cur)
            idx+=1
    if loop_end-1>=n:
        return lst[n]
    n-=loop_begin
    loop_length=loop_end-loop_begin
    lst=lst[loop_begin:]
    return lst[n%(loop_length)]

A,N,M=map(int,readline().split())
mod=M*M
for p in Factorize(M):
    mod*=(p-1)
    mod//=p
ans=Permutation_Product(1,N,lambda x:pow(A,x,mod))%M
print(ans)
0