結果

問題 No.887 Collatz
ユーザー test
提出日時 2020-09-11 17:03:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 367 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 195,624 KB
最終ジャッジ日時 2025-01-14 09:40:25
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void solve() {
  int N;
  cin >> N;
  vector<int> v{N};
  while (N != 1) {
    if (N % 2)
      N = N * 3 + 1;
    else
      N /= 2;
    v.emplace_back(N);
  }
  cout << v.size() - 1 << endl;
  cout << *max_element(v.cbegin(), v.cend()) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
0