結果
問題 | No.634 硬貨の枚数1 |
ユーザー |
|
提出日時 | 2018-04-15 12:08:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 459 bytes |
コンパイル時間 | 2,097 ms |
コンパイル使用メモリ | 193,016 KB |
最終ジャッジ日時 | 2025-01-05 10:15:15 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 75 |
ソースコード
#include <bits/stdc++.h> using namespace std; bool is_tri(int n) { int sn = sqrt(n * 2) + 1e-9; return sn * (sn + 1) / 2 == n; } signed main() { ios::sync_with_stdio(false); int N; cin >> N; int ans = 3; if (is_tri(N)) { ans = 1; } else { for (int i = 1; ; ++i) { int x = i * (i + 1) / 2; if (x > N) break; if (is_tri(N - x)) { ans = 2; break; } } } cout << ans << endl; return 0; }