結果
問題 |
No.634 硬貨の枚数1
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:28:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 599 bytes |
コンパイル時間 | 229 ms |
コンパイル使用メモリ | 82,720 KB |
実行使用メモリ | 68,524 KB |
最終ジャッジ日時 | 2025-03-20 20:29:06 |
合計ジャッジ時間 | 5,705 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 75 |
ソースコード
import math N = int(input()) def is_tri(x): if x <= 0: return False s = 8 * x + 1 sqrt_s = math.isqrt(s) if sqrt_s * sqrt_s != s: return False k = (sqrt_s - 1) // 2 return k * (k + 1) // 2 == x if is_tri(N): print(1) else: k_max = (math.isqrt(8 * N + 1) - 1) // 2 found = False for k in range(k_max, 0, -1): c1 = k * (k + 1) // 2 remaining = N - c1 if remaining < 0: continue if is_tri(remaining): print(2) found = True break if not found: print(3)