結果
| 問題 |
No.2007 Arbitrary Mod (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-15 21:43:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 981 bytes |
| コンパイル時間 | 256 ms |
| コンパイル使用メモリ | 82,420 KB |
| 実行使用メモリ | 52,224 KB |
| 最終ジャッジ日時 | 2024-06-27 17:19:30 |
| 合計ジャッジ時間 | 3,977 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
import sys
input = sys.stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput(): return list(map(int, input().split()))
def miinput(): return map(int, input().split())
def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
def mi0input(): return map(lambda x: int(x) - 1, input().split())
INF = 10**20
MOD = 998244353
modpowmemo = dict()
def modpow(a: int, p: int, mod: int) -> int:
if (a, p, mod) in modpowmemo:
return modpowmemo[(a, p, mod)]
# return a**p (mod MOD) O(log p)
if p == 0:
return 1
if p % 2 == 0:
half = modpow(a, p // 2, mod)
tmp = half * half % mod
modpowmemo[(a, p, mod)] = tmp
return tmp
else:
tmp = a * modpow(a, p - 1, mod) % mod
modpowmemo[(a, p, mod)] = tmp
return tmp
a, n = miinput()
print(MOD)
print(modpow(a, n, MOD))