結果

問題 No.2193 メガの下1桁
ユーザー shobonvipshobonvip
提出日時 2023-01-13 22:53:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,265 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 72,340 KB
最終ジャッジ日時 2023-08-26 04:38:53
合計ジャッジ時間 5,717 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
72,084 KB
testcase_01 AC 88 ms
71,896 KB
testcase_02 AC 93 ms
72,168 KB
testcase_03 AC 88 ms
72,060 KB
testcase_04 AC 90 ms
72,260 KB
testcase_05 AC 87 ms
72,184 KB
testcase_06 AC 87 ms
72,164 KB
testcase_07 AC 88 ms
72,152 KB
testcase_08 AC 86 ms
72,340 KB
testcase_09 AC 85 ms
72,176 KB
testcase_10 AC 92 ms
72,080 KB
testcase_11 AC 88 ms
72,308 KB
testcase_12 AC 89 ms
72,068 KB
testcase_13 AC 89 ms
72,148 KB
testcase_14 AC 90 ms
72,092 KB
testcase_15 AC 89 ms
71,944 KB
testcase_16 AC 88 ms
71,944 KB
testcase_17 AC 86 ms
72,312 KB
testcase_18 WA -
testcase_19 AC 86 ms
72,268 KB
testcase_20 AC 89 ms
72,064 KB
testcase_21 WA -
testcase_22 AC 88 ms
72,188 KB
testcase_23 AC 89 ms
72,096 KB
testcase_24 AC 85 ms
72,176 KB
testcase_25 AC 88 ms
71,984 KB
testcase_26 AC 87 ms
72,200 KB
testcase_27 AC 87 ms
72,260 KB
testcase_28 AC 88 ms
72,188 KB
testcase_29 WA -
testcase_30 AC 88 ms
71,876 KB
testcase_31 WA -
testcase_32 AC 85 ms
71,904 KB
testcase_33 AC 88 ms
72,096 KB
testcase_34 AC 86 ms
72,308 KB
testcase_35 AC 89 ms
72,328 KB
testcase_36 AC 89 ms
72,172 KB
testcase_37 AC 87 ms
72,328 KB
testcase_38 AC 88 ms
72,068 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import random

while True:
	"""
	m = random.randrange(0, 10)
	d = random.randrange(0, 10)
	n = random.randrange(0, 1000)
	b = random.randrange(2, 12)
	"""
	m = int(input())
	d = int(input())
	n = int(input())
	b = int(input())

	"""
	m = 9
	d = 3
	n = 82
	b = 9
	"""
	def fast(m,d,n,b):
		v = [[0] * b for i in range(60)]
		for i in range(b):
			if (i+d)%b != 0:
				v[0][i] = pow(i+d, i, b)
			else:
				v[0][i] = 0

		for i in range(59):
			for j in range(b):
				v[i+1][j] = v[i][v[i][j]]

		if n == 0:
			r = '0123456789ABCDEFG'
			return r[m % b]

		if m == 0:
			n -= 1
			if d == 0:
				m = 1
			else:
				if (m + d) % b == 0:
					m = 0
				else:
					m = pow(m+d, m, b)

		m %= b
		for i in range(60):
			if (n >> i) & 1:
				m = v[i][m]

		r = '0123456789ABCDEFG'
		return r[m]

	def naive(m,d,n,b):
		if n == 0:
			r = '0123456789ABCDEFG'
			return r[m % b]
		if m == 0:
			n -= 1
			if d == 0:
				m = 1
			else:
				if (m + d) % b == 0:
					m = 0
				else:
					m = pow(m+d, m, b)
		m %= b
		for i in range(n):
			if (m+d)%b != 0:
				m = pow(m+d, m, b)
			else:
				m = 0
		
		r = '0123456789ABCDEFG'

		return r[m]

	#if fast(m,d,n,b) != naive(m,d,n,b):
	#	print(m,d,n,b)
	#	print(fast(m,d,n,b), naive(m,d,n,b))
	#	break
	print(fast(m,d,n,b))
	break
0