結果
問題 |
No.2426 Select Plus or Minus
|
ユーザー |
|
提出日時 | 2024-06-10 23:48:18 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 565 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 12,032 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2025-01-03 01:20:58 |
合計ジャッジ時間 | 3,583 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
def reduce_number(N): m = N operations = [] while m != 1: if m % 2 == 0: m //= 2 operations.append('/') else: if m == 3 or (3 * m + 1) % 4 == 0: m = 3 * m + 1 operations.append('+') else: m = 3 * m - 1 operations.append('-') if len(operations) > 10000: raise ValueError("z") return operations N = int(input()) operations = reduce_number(N) print(len(operations)) print(''.join(operations))