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.BigInteger;
  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. BigInteger start = new BigInteger("1");
  14. BigInteger limit = new BigInteger("10");
  15. BigInteger zap1 = new BigInteger("0");
  16. BigInteger zap2 = new BigInteger("0");
  17. BigInteger n2 = new BigInteger("2"); // formula(1) progressiva
  18. BigInteger n4 = new BigInteger("4"); // formula(2) progressiva
  19. BigInteger soma1 = new BigInteger("1"); // número(1) estabelecido
  20. BigInteger soma2 = new BigInteger("3"); // número(2) estabelecido
  21.  
  22. for (BigInteger a = start, b=start; a.compareTo(limit) <= 0 && b.compareTo(limit) <= 0;) {
  23.  
  24. int comparacao = zap1.add(soma1).compareTo(zap2.add(soma2));
  25.  
  26. if (comparacao == 0 && zap1.compareTo(BigInteger.ZERO) != 0 && zap2.compareTo(BigInteger.ZERO) != 0) {
  27. System.out.println(zap1.add(BigInteger.ONE));
  28. }
  29.  
  30. if (comparacao <= 0) {
  31.  
  32. zap1 = zap1.add(n2.multiply(a)); // formula(1) progressiva
  33. a = a.add(BigInteger.ONE);
  34. }
  35. else {
  36.  
  37. zap2 = zap2.add(n4.multiply(b)); // formula(2) progressiva
  38. b = b.add(BigInteger.ONE);
  39. }
  40.  
  41. }
  42. }
  43. }
Success #stdin #stdout 0.08s 27920KB
stdin
Standard input is empty
stdout
7
43