fork(1) download
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
        int quotient = 0;
        int a = 123;
        int b = 5;
        int bfirst = b;
        String a1 = Integer.toBinaryString(a);
        String b1 = Integer.toBinaryString(b);
        int aLength = a1.length();
        int bLength = b1.length();
        int power = aLength - bLength;
        b =(int) (b * Math.pow(2, power)); 
        System.out.println(aLength + " " + bLength + " " + power);

        while(a >= bfirst) {
        	System.out.print(a + " ");
        	System.out.print(b + " ");
        	System.out.println(quotient);
            if(a >= b) {
            	aLength = Integer.toBinaryString(a).length();
            	bLength = Integer.toBinaryString(b).length();
            	int bfirstLength = Integer.toBinaryString(bfirst).length();
                a = a-b;
                quotient = quotient*2+1;
                b = b/2;
                if (a < bfirst) {
                	quotient = quotient * (int)Math.pow(2, bLength - bfirstLength);
                }
            } else {
                quotient = quotient*2;
                b = b/2;
            }
        }
        System.out.println(quotient);

	}
}
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
7 3 4
123 80 0
43 40 1
24