結果

問題 No.2534 コラッツ数列
ユーザー 👑 p-adic
提出日時 2023-08-26 16:06:32
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 67,332 KB
最終ジャッジ日時 2025-02-16 14:40:07
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
using ll = long long;
int main()
{
  ll N; cin >> N;
  constexpr const int bound_c = 50;
  int c = 0;
  int line = 2;
  while( c++ < bound_c ){
    if( line == 2 ){
      line = ( N == 1 ? 4 : line + 1 );
    } else if( line == 4 ){
      break;
    } else if( line == 3 ){
      N = ( N % 2 == 0 ? N / 2 : 3 * N + 1 );
      line = 2;
    }
  }
  if( c <= bound_c ){
    cout << "Yes\n";
    cout << c;
    return 0;
  }
  cout << "No\n";
  return 0;
}
0