পৃষ্ঠাসমূহ

শনিবার, ৬ মে, ২০১৭

uva 100

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package uva100;

import java.util.Scanner;

class Main {

    public static void main(String[] args) {
       
        Scanner scanner = new Scanner(System.in);
        int i,j,c, max = 0, first, last;
        while(scanner.hasNextInt()) {
            i=scanner.nextInt();
            j=scanner.nextInt();
            max = 0;
            if (j>i) {
                first = i;
                last = j;
            } else {
                first = j;
                last = i;
            }
       
            for (int start = first; start<=last; start++) {
                c = 1;
               
                int num = start;
                while (num != 1) {
                    c++;
           
                    if (num % 2 == 1){
                        num = (3*num) + 1;
                    } else {
                        num = num / 2;
                    }
                }
                if (c > max) max = c;
            }
            System.out.println(i + " " + j + " "+ max);
        }
    }
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন