2011年8月2日

UVa - p100

p100 問題連結

import java.io.BufferedInputStream;
import java.util.Scanner;

public class u100 {
	int max;
	int min;
	int cont;
	public u100(){
		Scanner sc = new Scanner(new BufferedInputStream(System.in));
		String s;
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a > b){
				max = a;
				min = b;
			}else{
				max = b;
				min = a;
			}
			int contmax = 0;
			for(; min <= max ; min++){
				cont = 0;
				f(min,max);
				if(contmax < cont)
					contmax = cont;
			}
			System.out.println(a + " " + b + " " + contmax);
		}
	}
	
	public void f(int n , int j){
		//System.out.print(n + " ");
		cont++;
		if(n == 1){
			//stop
		}else{
			if(n%2==1){
				n = 3*n+1;
			}else{
				n = n/2;
			}
			f(n,j);
		}
	}
	
	public static void main(String[] args){
		new u100();
	}
}

沒有留言: