Created
December 27, 2011 05:19
-
-
Save janoulle/1522780 to your computer and use it in GitHub Desktop.
Problem 6 - Project Euler in Java by Jane Ullah
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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