개발자/algorithm
CSES : Weird Algorithm (c++)
성찬쿤
2020. 6. 14. 13:27
https://cses.fi/problemset/task/1068
CSES - Weird Algorithm
cses.fi
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
while (1) {
cout << n << " ";
if (n == 1) break;
if (n % 2 == 0) n /= 2;
else n = n * 3 + 1;
}
return 0;
}