結果
| 問題 |
No.2534 コラッツ数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-10 21:57:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 530 bytes |
| コンパイル時間 | 4,073 ms |
| コンパイル使用メモリ | 249,424 KB |
| 最終ジャッジ日時 | 2025-02-17 20:44:02 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
ll n;
void solve(){
if(n<=0){
cout<<"No"<<endl;
return;
}
int cnt = 0;
while(1){
cnt += 2;
if(n==1){
break;
}else{
if(n%2==0){
n/=2;
}else{
n = n*3+1;
}
}
}
if(cnt>50){
cout<<"No"<<endl;
}else{
cout<<"Yes"<<endl;
cout<<cnt<<endl;
}
}
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n;
solve();
}