Skip to content

Instantly share code, notes, and snippets.

@janoulle
Created December 27, 2011 05:19
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 janoulle/1522780 to your computer and use it in GitHub Desktop.
Save janoulle/1522780 to your computer and use it in GitHub Desktop.
Problem 6 - Project Euler in Java by Jane Ullah
/**
* @author Jane Ullah
* @purpose Problem 6 - Project Euler
* @date 12/26/2011
* @site http://janetalkscode.com
*/
public class Problem6 {
public static void main(String[] args) {
int sumSquares = 0, squareSums = 0;
int num = 100;
//Use summation formula for quadratic series: (n*(n+1)*(2n+1))/6
sumSquares = (num*(num+1)*(2*num+1))/6;
//Use Euler's trick for summations: (n(n+1))/2
squareSums = (int) Math.pow(((num*(num+1))/2),2);
System.out.println(squareSums - sumSquares);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment