結果
問題 | No.887 Collatz |
ユーザー |
![]() |
提出日時 | 2019-09-20 21:24:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 459 bytes |
コンパイル時間 | 1,555 ms |
コンパイル使用メモリ | 166,848 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 16:11:11 |
合計ジャッジ時間 | 2,484 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include<bits/stdc++.h>#define int long longusing namespace std;signed main(){cin.tie(0);ios::sync_with_stdio(false);int N; cin>>N;if(N==1){cout<<0<<endl;cout<<1<<endl;return 0;}int Max=N;for(int i=1;;i++){if(N%2==0) N/=2;else N=3*N+1;Max=max(Max,N);if(N==1){cout<<i<<endl;cout<<Max<<endl;return 0;}}}