Advertisement
Guest User

Untitled

a guest
Jul 29th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Main {
  6.  
  7.         public static void main(String[] args) throws NumberFormatException, IOException{
  8.  
  9.                 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  10.                 String line;
  11.                 while((line = in.readLine()) != null){
  12.                         int[] pairs = new int[2];
  13.                         int x = 0;
  14.                         for(String i : line.split(" ")){
  15.                             if(line.split(" ").length == 2){
  16.                                 pairs[x] = Integer.parseInt(i);
  17.                                 x++;
  18.                             }
  19.                         }
  20.                         blah(pairs[0], pairs[1]);
  21.                 }
  22.                
  23.         }
  24.        
  25.         public static void blah(int num1, int num2){
  26.            
  27.                 final int cNum1 = num1;
  28.                 final int cNum2 = num2;
  29.                 int max = 0;
  30.                 int counter = 0;
  31.                
  32.                 if(num1 > num2){
  33.                        
  34.                         int temp = num1;
  35.                         num1 = num2;
  36.                         num2 = temp;
  37.                 }
  38.                
  39.                 for(int x = num1; x <= num2; x++){
  40.                         counter = 0;
  41.                         int j = x;
  42.                   while(j != 1){
  43.                           counter++;
  44.                           if( j % 2 == 0){
  45.                                   j = j / 2;
  46.                           }
  47.                           else{
  48.                                   j = (j * 3) + 1;
  49.                           }
  50.                   }
  51.                   if(counter > max){
  52.                       max = counter;
  53.                   }
  54.                        
  55.                 }
  56.                
  57.                 System.out.println(cNum1 + " " + cNum2 + " " + max);
  58.                
  59.         }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement