Files
cses/CSES - CSES Problem Set/Introducotry_Problems/Weird_Algorithm.cpp
2024-06-03 16:57:59 +02:00

24 lines
326 B
C++

// Weird Algorithm
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n;
cin >> n;
while (n != 1) {
cout << n << " ";
if (n & 1) {
n *= 3;
n++;
} else {
n /= 2;
}
}
cout << n << endl;
return 0;
}