3n+1水题....
AC代码:
import java.util.Scanner; /** * @author CC11001100 */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(resolve(sc.nextInt())); } private static int resolve(int n){ if(n==1) return 0; else return 1 + resolve(n%2==0 ? n/2 : (3*n+1)/2); } }
题目来源: https://www.nowcoder.com/pat/2/problem/4067
.