結果
問題 | No.887 Collatz |
ユーザー |
![]() |
提出日時 | 2019-09-22 06:16:36 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 385 bytes |
コンパイル時間 | 1,414 ms |
コンパイル使用メモリ | 157,276 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 03:23:03 |
合計ジャッジ時間 | 2,243 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; int collatz(int n) { if (n % 2 == 0) { return n / 2; } else { return 3 * n + 1; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int i = 0, nmax = n; while (n != 1) { n = collatz(n); i++; nmax = max(nmax, n); } cout << i << '\n'; cout << nmax << '\n'; return 0; }