結果
問題 |
No.181 A↑↑N mod M
|
ユーザー |
![]() |
提出日時 | 2020-04-10 12:46:03 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 541 ms / 5,000 ms |
コード長 | 595 bytes |
コンパイル時間 | 120 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,488 KB |
最終ジャッジ日時 | 2024-09-14 22:15:24 |
合計ジャッジ時間 | 25,201 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 37 |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np U = int(10 ** 4) phi = np.arange(U) for p in range(2, U): if phi[p] == p: phi[::p] -= phi[::p] // p def f(A, N, M): if A == 1: return 1 if N == 0: return 1 if M == 1: return 1 MM = int(phi[M]) x = f(A, N - 1, MM) if x >= MM or x >= 20: return M + pow(A, x, M) x = A ** x if x >= M: return (x % M) + M return x A, N, M = map(int, read().split()) print(f(A, N, M) % M)