fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. RecursiveCounter c = new RecursiveCounter();
  14. c.count(46342);
  15. }
  16. }
  17.  
  18. class RecursiveCounter {
  19. public BigInteger count(int number) {
  20. return count(1, number);
  21. }
  22.  
  23. public BigInteger count(int from, int to) {
  24. int middle = (from + to) >> 1;
  25. BigInteger left;
  26. BigInteger right;
  27. if (middle - from > 1)
  28. left = count(from, middle);
  29. else {
  30. if (from * middle < 0) {
  31. System.out.println(from+"*"+middle+"="+(from*middle));
  32. }
  33. left = new BigInteger(String.valueOf(from * middle));
  34. }
  35. if (to - (middle + 1) > 1)
  36. right = count(middle + 1, to);
  37. else {
  38. if ((middle+1)*to < 0) {
  39. System.out.println((middle+1)+"*"+to+"="+((middle+1)*to));
  40. }
  41. right = to == middle + 1 ? new BigInteger(String.valueOf(to)) : new BigInteger(String.valueOf((middle + 1) * to));
  42. }
  43. return left.multiply(right);
  44. }
  45. }
  46.  
Success #stdin #stdout 0.51s 97924KB
stdin
Standard input is empty
stdout
46341*46342=-2147432674