結果

問題 No.2766 Delicious Multiply Spice
ユーザー Kude
提出日時 2024-05-31 21:39:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 389 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 56,624 KB
最終ジャッジ日時 2024-12-20 22:51:37
合計ジャッジ時間 3,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache
@cache
def f(n):
    if n == 1:
        return True
    n -= 1
    return n % 2 == 0 and f(n // 2) or n % 3 == 0 and f(n // 3)

n = int(input())
ans = []
while n != 1:
    n -= 1
    if n % 2 == 0 and f(n // 2):
        n //= 2
        ans.append('A')
    else:
        assert n % 3 == 0
        n //= 3
        ans.append('B')
ans.reverse()
print(''.join(ans))
0