1. 程式人生 > >[PTA] 1001. 害死人不償命的(3n+1)猜想 (Basic)

[PTA] 1001. 害死人不償命的(3n+1)猜想 (Basic)

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int times = 0;
        while (n != 1) {
            if (1 == (n & 1)) {
                n = (3 * n + 1) >> 1;
            } else {
                n = n >> 1;
            }
            ++times;
        }

        System.out.print(times);
        sc.close();
    }
}