結果

問題 No.181 A↑↑N mod M
ユーザー shobonvipshobonvip
提出日時 2022-04-09 09:37:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,136 bytes
コンパイル時間 1,283 ms
コンパイル使用メモリ 86,668 KB
実行使用メモリ 71,888 KB
最終ジャッジ日時 2023-08-19 13:28:18
合計ジャッジ時間 6,489 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,280 KB
testcase_01 AC 73 ms
71,236 KB
testcase_02 AC 75 ms
71,608 KB
testcase_03 AC 75 ms
71,056 KB
testcase_04 AC 76 ms
71,640 KB
testcase_05 AC 74 ms
71,600 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 75 ms
71,888 KB
testcase_09 WA -
testcase_10 AC 74 ms
71,460 KB
testcase_11 AC 75 ms
71,740 KB
testcase_12 AC 74 ms
71,796 KB
testcase_13 AC 75 ms
71,772 KB
testcase_14 AC 73 ms
71,744 KB
testcase_15 AC 75 ms
71,464 KB
testcase_16 AC 74 ms
71,668 KB
testcase_17 AC 74 ms
71,328 KB
testcase_18 AC 73 ms
71,388 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 74 ms
71,116 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 73 ms
71,664 KB
testcase_26 AC 73 ms
71,460 KB
testcase_27 AC 74 ms
71,172 KB
testcase_28 AC 73 ms
71,752 KB
testcase_29 AC 73 ms
71,120 KB
testcase_30 AC 74 ms
71,328 KB
testcase_31 AC 75 ms
70,904 KB
testcase_32 AC 75 ms
71,336 KB
testcase_33 AC 74 ms
71,620 KB
testcase_34 AC 75 ms
71,676 KB
testcase_35 AC 72 ms
71,520 KB
testcase_36 AC 74 ms
71,616 KB
testcase_37 AC 73 ms
71,608 KB
testcase_38 AC 75 ms
71,668 KB
testcase_39 AC 75 ms
71,788 KB
testcase_40 AC 75 ms
71,744 KB
testcase_41 WA -
testcase_42 AC 73 ms
71,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

def xgcd(a,b):
	prevx, nextx = 1, 0
	prevy, nexty = 0, 1
	while b:
		quotient = a//b
		nextx, prevx = prevx - quotient * nextx, nextx
		nexty, prevy = prevy - quotient * nexty, nexty
		a, b = b, a % b
		#print(a,b)
	return prevx, prevy,a

def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf

def euler(m):
	tmp = pfact(m)
	ans = 1
	for i, j in tmp.items():
		ans = ans * (i**(j-1)) * (i-1)
	return ans

def perfectdecompose(d, u):
	for i in range(2,int(d**0.5)+1):
		while d%i == 0:
			d//=i
		while u%i == 0:
			u//=i
	if d>1:
		while u%d == 0:
			u//=d
	return u

def tetinf(n, u):
	if u == 1:
		return 0
	d = gcd(n, u)
	pf = perfectdecompose(d, u)
	return pow(n, tetinf(n, euler(pf)), pf) * (u//pf) * xgcd(u//pf, pf)[0] % u

n,k,m = map(int,input().split())
if k >= 4 and n >= 3:
	print(tetinf(n, m))
elif n == 2 and k == 4:
	print(65536 % m)
elif k == 3:
	if n % m == 0 and pow(n, n, m) == 0:
		print(0)
	else:
		print(pow(n, pow(n, n, m), m))
elif k == 2:
	print(pow(n, n, m))
elif k == 1:
	print(n % m)
else:
	print(1)
0