結果
問題 | No.887 Collatz |
ユーザー |
![]() |
提出日時 | 2019-09-21 11:48:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,311 bytes |
コンパイル時間 | 2,639 ms |
コンパイル使用メモリ | 211,332 KB |
最終ジャッジ日時 | 2025-01-07 18:55:03 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } template<class S, class T> inline S chmax(S &a, T b){ if(a<b){ a=b; } return a; } int main(){ int N; int res1; int res2; rd(N); res1 = 0; res2 = N; while(N > 1){ if(N%2){ N =3*N+1; } else{ N =N/2; } res1++; chmax(res2, N); } wt_L(res1); wt_L('\n'); wt_L(res2); wt_L('\n'); return 0; } // cLay varsion 20190921-1 // --- original code --- // { // int N, res1, res2; // rd(N); // res1 = 0; // res2 = N; // while(N > 1){ // N = if[N%2, 3N+1, N/2]; // res1++; // res2 >?= N; // } // wtLn(res1, res2); // }