fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int quotient = 0;
  13. int a = 123;
  14. int b = 5;
  15. int bfirst = b;
  16. String a1 = Integer.toBinaryString(a);
  17. String b1 = Integer.toBinaryString(b);
  18. int aLength = a1.length();
  19. int bLength = b1.length();
  20. int power = aLength - bLength;
  21. b =(int) (b * Math.pow(2, power));
  22. System.out.println(aLength + " " + bLength + " " + power);
  23.  
  24. while(a >= bfirst) {
  25. System.out.print(a + " ");
  26. System.out.print(b + " ");
  27. System.out.println(quotient);
  28. if(a >= b) {
  29. aLength = Integer.toBinaryString(a).length();
  30. bLength = Integer.toBinaryString(b).length();
  31. int bfirstLength = Integer.toBinaryString(bfirst).length();
  32. a = a-b;
  33. quotient = quotient*2+1;
  34. b = b/2;
  35. if (a < bfirst) {
  36. quotient = quotient * (int)Math.pow(2, bLength - bfirstLength);
  37. }
  38. } else {
  39. quotient = quotient*2;
  40. b = b/2;
  41. }
  42. }
  43. System.out.println(quotient);
  44.  
  45. }
  46. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
7 3 4
123 80 0
43 40 1
24