알고리즘

[알고리즘] 백준 14920 - 3n+1 수열 (C++)

blueberrysoda 2025. 2. 13. 23:25

[문제 링크] : https://www.acmicpc.net/problem/14920

#include <iostream>
using namespace std;

int Ans = 0;

int solve(int n){
    Ans++;
    if(n == 1){
        return 0;
    }

    if(n % 2 == 0){
        return solve(n / 2);
    }
    else{
        return solve(3 * n + 1);
    }
}

int main(){
    int N;
    cin >> N;
    solve(N);
    cout << Ans << "\n";
    return 0;
}