Project Euler | Problem 6 | Sum square difference
Problem Description :
The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385. The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^2 = 55^2 = 3025. Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640. Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum?
Concept :
This is a very simple problem. We have to apply following two properties to solve this problem mathematically.
- Sum of first N natural numbers is N(N+1)/2.
- Sum of square of first N natural numbers is N(N+1)(2N+1)/6
Java Program :
Output :
References :
http://www.9math.com/book/sum-first-n-natural-numbers
http://www.9math.com/book/sum-squares-first-n-natural-numbers
Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.
Tags : Project Euler Problem 6 solution in Java, Sum square difference, Mathematics problems, Sum of first n natural number, sum of square of first n natural numbers.
Project Euler | Problem 6 | Sum square difference
Reviewed by Rohit Agarwal
on
1/11/2017
Rating:
No comments:
Please provide your valuable comments. If you have any suggestion please share with me I will work on it and if you have any question or doubt please ask, don't hesitate. I am your friend, i will clarify all your doubts.