[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();}
}
posted @
2018-11-16 00:29 Ruoh3kou 阅读(
...) 评论(
...) 编辑 收藏