[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();
    }
}

猜你喜欢

转载自www.cnblogs.com/ruoh3kou/p/9967043.html