package com.example.foo; import java.math.BigInteger; public class SomeClass { public static void main(final String[] args) { BigInteger x = BigInteger.ZERO; BigInteger value = BigInteger.ZERO; for (int i = 1; i < 100; i++) { BigInteger e = BigInteger.ZERO; for (int j = 1; j <= i; j++) { BigInteger product = BigInteger.ONE; for (long k = 0; k < j; k++) product = product.multiply(x = x.add(BigInteger.ONE)); e = e.add(product); } value = value.add(e); System.out.format("Expression %d : %d%n", i, e); // System.out.format("Value : %d%n", value); } // System.out.println(value); } }