結果
| 問題 |
No.887 Collatz
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-11 17:13:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 444 bytes |
| コンパイル時間 | 2,171 ms |
| コンパイル使用メモリ | 193,500 KB |
| 最終ジャッジ日時 | 2025-01-14 09:40:44 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
void solve() {
int N, i = 0, ans = 0;
cin >> N;
ans = N;
while (N != 1) {
if (N % 2)
N = N * 3 + 1;
else
N /= 2;
chmax(ans, N);
i++;
}
cout << i << endl;
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
}