import java.util.Scanner;
public class test_100 {
public static int count(int n,int s){
if(n==1){
return s;
}else if(n%2!=0){
return count(3*n+1,s+1);
}else{
return count(n/2,s+1);
}
}
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
int i = in.nextInt();
int j = in.nextInt();
int n = 0;
for(;i<j;i++){
n=Math.max(count(i,1),count(i+1,1));
}
System.out.println(n);
}
}
我的程式碼為這樣,如何讓電腦可以AP呢......
while (in.hasNextInt()) {
i = in.nextInt();
...
...
}