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

it2025-11-15  2

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

转载于:https://www.cnblogs.com/ruoh3kou/p/9967043.html

最新回复(0)