# Weird Algorithm

{% embed url="https://cses.fi/problemset/task/1068" %}

{% tabs %}
{% tab title="C++" %}
```cpp
#include <iostream>
using namespace std;
 
void solution(long n){
    while(n != 1){
        cout << n << " ";
        if(n % 2 == 0){
            n = n / 2;
        }
        else{
            n = n * 3 + 1;
        }
    } 
    cout << 1;
}
 
int main() {
    long input;
    cin >> input;
    solution(input);
    return 0;
}
```
{% endtab %}
{% endtabs %}
