結果
問題 | No.181 A↑↑N mod M |
ユーザー |
![]() |
提出日時 | 2023-12-08 04:15:54 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 937 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-09-27 02:38:27 |
合計ジャッジ時間 | 2,820 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 30 WA * 7 |
ソースコード
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)