UVA 100 Java

import java.util.*;

public class main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    while(sc.hasNextInt())
    {
    	int num1 = sc.nextInt();
    	int num2 = sc.nextInt();
    	int max_n = Math.max(num1, num2);
    	int min_n = Math.min(num1, num2);
    	int max = 0;
    	for(int i = min_n; i <= max_n; i++)
    	{
    		int n = i;
    		int count = 1;
    		while(n != 1)
    		{
    			count++;
    			if(n%2 == 1)
    				n=3*n+1;
    			else
    				n = n / 2;
    		}
    		if(count > max)
    			max = count;
    	}
    	System.out.printf("%d %d %d\r\n", num1, num2, max);
    }
  }
};

留言

這個網誌中的熱門文章

C# 井字遊戲