結果
| 問題 |
No.887 Collatz
|
| コンテスト | |
| ユーザー |
kyort0n
|
| 提出日時 | 2019-09-20 21:23:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 844 bytes |
| コンパイル時間 | 1,612 ms |
| コンパイル使用メモリ | 165,336 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 16:09:00 |
| 合計ジャッジ時間 | 2,376 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int main() {
//cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll maxi = n;
for(int timer = 0; ; timer++) {
if(n == 1) {
cout << timer << endl << maxi << endl;
return 0;
}
if(n % 2 == 0) n = n / 2;
else n = 3 * n + 1;
chmax(maxi, n);
}
return 0;
}
kyort0n