Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created November 17, 2016 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchir/825aef1145ae126e8f1f9aaa2936a70c to your computer and use it in GitHub Desktop.
Save olegchir/825aef1145ae126e8f1f9aaa2936a70c to your computer and use it in GitHub Desktop.
import java.math.BigInteger;
class Sum2 {
private static final BigInteger MIN = BigInteger.ONE;
private static final BigInteger MAX = new BigInteger("10000000000");
private static final BigInteger TWO = new BigInteger("2");
public static void main(String[] args) {
long start = System.nanoTime();
final BigInteger result = (MIN.add(MAX)).multiply(MAX.divide(TWO)); //Hi from mister Gauss, motherfuckers!
long end = System.nanoTime();
long microseconds = (end - start) / 1000;
System.out.println(String.format("Result: %s", result.toString()));
System.out.println(String.format("Execution time: %d", microseconds));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment