I have two progressive formulas of 10 numbers. Each of them will add up to a certain number.
The first formula thus progresses 0+2+4+6+8+10+12+14+16+18+20
.
And its result is ( 2,6,12,20,30,42,56,72,90,110
).
Adding this result to an established number, in the "1"
case.
Final result will be: ( 3,7,13,21,31,43,57,73,91,111
).
The second formula thus progresses 0+4+8+12+16+20+24+28+32+36+40
.
And its result is ( 4,12,24,40,60,84,112,144,180,220
).
Adding this result to an established number, in the "3"
case.
Final result will be: ( 7,15,27,43,63,87,115,147,183,223
).
Code:
public static void main(String[] args) {
BigInteger start = new BigInteger("1");
BigInteger limit = new BigInteger("10");
BigInteger zap1 = new BigInteger("0");
BigInteger zap2 = new BigInteger("0");
BigInteger n2 = new BigInteger("2"); //formula(1) progressiva
BigInteger n4 = new BigInteger("4"); //formula(2) progressiva
BigInteger soma1 = new BigInteger("1"); //número(1) estabelecido
BigInteger soma2 = new BigInteger("3"); //número(2) estabelecido
for (BigInteger a = start; a.compareTo(limit) <= 0; a = a.add(BigInteger.ONE)) {
zap1 = zap1.add(n2.multiply(a)); //formula(1) progressiva
zap2 = zap2.add(n4.multiply(a)); //formula(2) progressiva
BigInteger copas1 = zap1.add(soma1); //Resultado final(1)
BigInteger copas2 = zap2.add(soma2); //Resultado final(2)
System.out.println( copas1 );
System.out.println( copas2 );
}
}
See working on repl: link
Final result of the first formula: ( 3,7,13,21,31,43,57,73,91,111
).
Final result of the second formula: ( 7,15,27,43,63,87,115,147,183,223
).
Comparing the final results of the two formulas we see that the repeated numbers are:
The 7
and 43
.
So the output of the program should only print:
7
43
Important to note that: It can not be in ArrayList
, and the numbers must be BigInteger
.