結果
| 問題 | No.634 硬貨の枚数1 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-15 12:08:46 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 459 bytes |
| 記録 | |
| コンパイル時間 | 1,321 ms |
| コンパイル使用メモリ | 209,452 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-06 23:09:21 |
| 合計ジャッジ時間 | 3,667 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}