結果

問題 No.887 Collatz
ユーザー d_sei
提出日時 2019-10-13 19:04:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 515 bytes
コンパイル時間 1,139 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-16 07:28:20
合計ジャッジ時間 1,966 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long int lint;
int main() {
	lint n0;
	cin >> n0;
	if (n0 == 1) {
		cout << 0 << endl << 1 << endl;
	}
	else {
		vector<lint>vec(1000);
		int cnt = 0;
		while (n0 > 1) {
			vec.at(cnt) = n0;
			if (n0 % 2) {
				n0 = 3 * n0 + 1;
			}
			else {
				n0 = n0 / 2;
			}
			cnt++;
		}
		sort(vec.begin(), vec.end());
		cout << cnt << endl << vec.at(999) << endl;
	}



	

}



	
0