結果

問題 No.887 Collatz
ユーザー acchan
提出日時 2019-10-04 11:45:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 301 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 66,752 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-03 06:48:41
合計ジャッジ時間 1,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int N; cin >> N;
  int max_n = N;
  int cnt = 0;
  while(N != 1) {
    cnt++;
    if(N % 2 == 0) N = N/2;
    else N = 3 * N + 1;
    max_n = max(max_n, N);
  }
  cout << cnt << endl;
  cout << max_n << endl;
  return 0;
}
0