結果

問題 No.887 Collatz
ユーザー misora192misora192
提出日時 2019-10-07 07:24:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 412 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 167,112 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-12 12:23:56
合計ジャッジ時間 2,356 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	int cnt = 0;
	int nmax = n;
	while(true){
		if(n == 1){
			cout << cnt << endl;
			cout << nmax << endl;
			return 0;
		}

		if(n % 2 == 0){
			n /= 2;
		}else{
			n = 3 * n + 1;
			nmax = max(nmax, n);
		}
		cnt++;
	}
}
0