結果
問題 | No.887 Collatz |
ユーザー |
![]() |
提出日時 | 2019-09-20 21:32:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 924 bytes |
コンパイル時間 | 1,842 ms |
コンパイル使用メモリ | 167,120 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-14 16:33:03 |
合計ジャッジ時間 | 2,521 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h>using namespace std;using lint = long long int;using pint = pair<int, int>;using plint = pair<lint, lint>;#define ALL(x) (x).begin(), (x).end()#define SZ(x) ((lint)(x).size())#define POW2(n) (1LL << (n))#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)#define REP(i, n) FOR(i, 0, n)#define IREP(i, n) IFOR(i, 0, n)#ifdef LOCAL#define eprintf(...) fprintf(stderr, __VA_ARGS__)#else#define eprintf(...) 42#endifint main(){lint n;cin >> n;lint ans, tmp;lint ni = n;lint nmax = n;lint i = 0;while(ni!=1){if(ni%2==0){ni /= 2;}else{ni = 3 * ni + 1;}nmax = max(nmax, ni);i++;}cout << i <<"\n";cout << nmax << "\n";return 0;}