結果

問題 No.181 A↑↑N mod M
ユーザー vwxyzvwxyz
提出日時 2024-05-03 16:02:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,508 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 63,196 KB
最終ジャッジ日時 2024-05-03 16:02:12
合計ジャッジ時間 3,608 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,524 KB
testcase_01 AC 44 ms
54,784 KB
testcase_02 AC 42 ms
54,848 KB
testcase_03 AC 43 ms
54,596 KB
testcase_04 AC 43 ms
54,880 KB
testcase_05 AC 43 ms
54,460 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 42 ms
54,816 KB
testcase_10 WA -
testcase_11 AC 43 ms
55,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 43 ms
54,724 KB
testcase_19 AC 42 ms
54,228 KB
testcase_20 AC 42 ms
55,676 KB
testcase_21 AC 42 ms
54,412 KB
testcase_22 AC 42 ms
55,436 KB
testcase_23 WA -
testcase_24 AC 43 ms
55,068 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 43 ms
54,572 KB
testcase_28 WA -
testcase_29 AC 42 ms
54,120 KB
testcase_30 AC 42 ms
54,492 KB
testcase_31 WA -
testcase_32 AC 43 ms
55,428 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 42 ms
54,600 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def LCM(n,m):
    if n or m:
        return abs(n)*abs(m)//math.gcd(n,m)
    return 0

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)]

def Totient(N,mod):
    retu=N
    primes=list(Factorize(mod).keys())
    l=len(primes)
    dp_popcount=[0]*(1<<l)
    dp_count=[N]*(1<<l)
    for bit in range(1,1<<l):
        i=(bit&-bit).bit_length()-1
        dp_popcount[bit]=dp_popcount[bit^1<<i]+1
        dp_count[bit]=dp_count[bit^1<<i]//primes[i]
        if dp_popcount[bit]%2==0:
            retu+=dp_count[bit]
        else:
            retu-=dp_count[bit]
    return retu

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


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