結果

問題 No.2766 Delicious Multiply Spice
ユーザー shobonvip
提出日時 2024-05-31 22:49:22
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-12-21 00:45:33
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
d = dict()
d[1] = 1

def calc(x):
	if x in d: return d[x]
	if (x-1) % 2 == 0 and calc((x-1) // 2) == 1:
		d[x] = 1
		return 1
	if (x-1) % 3 == 0 and calc((x-1) // 3) == 1:
		d[x] = 1
		return 1
	d[x] = 0
	return 0

assert(calc(n))

x = n
a = []
while x > 1:
	if (x-1) % 2 == 0 and calc((x-1)//2) == 1:
		x = (x-1) // 2
		a.append('A')
	else:
		assert (x-1) % 3 == 0 and calc((x-1)//3) == 1
		x = (x-1) // 3
		a.append('B')

print(''.join(a[::-1]))
0