結果
| 問題 |
No.887 Collatz
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-11 17:09:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 453 bytes |
| コンパイル時間 | 3,069 ms |
| コンパイル使用メモリ | 192,748 KB |
| 最終ジャッジ日時 | 2025-01-14 09:40:36 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 22 WA * 6 |
ソースコード
#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;
vector<int> v{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();
}