Problem Solving Series(For Interview) (10 Part Series)
1 Multiples of 3 and 5 – Project Euler Solution
2 Two sum – Leet Code Solution
… 6 more parts…
3 Check for Armstrong Number
4 Largest palindrome product – Project Euler Solution
5 Smallest multiple – Project Euler Solution
6 Sum square difference – Project Euler Solution
7 10001st prime – Project Euler Soution
8 Sieve of Eratosthenes
9 Bubble Sort Implementation in Python
10 How to Solve Linear Equations with Matrix Inversion
Topic: Sum square difference
Problem Statement:
The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
Enter fullscreen mode Exit fullscreen mode
The square of the sum of the first ten natural numbers is,
(1+2+3...+10)^2 = 55^2 = 3025
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
You can find the original question here -> Project Euler
Largest palindrome product – Project Euler Solution
Deepak Raj ・ Aug 1 ’20
#challenge #python #computerscience #algorithms
Sum square difference – Project Euler Solution in python
def difference(n):
""" This program will return difference between the square of sum and sum of the square. """
sumOfSquare = 0
squareOfSum = 0
for i in range(n+1):
squareOfSum += i
sumOfSquare += i ** 2
return squareOfSum ** 2 - sumOfSquare
if __name__ == "__main__":
print(difference(100))
Enter fullscreen mode Exit fullscreen mode
Share Your Solutions for Sum square difference.
Problem Solving Series(For Interview) (10 Part Series)
1 Multiples of 3 and 5 – Project Euler Solution
2 Two sum – Leet Code Solution
… 6 more parts…
3 Check for Armstrong Number
4 Largest palindrome product – Project Euler Solution
5 Smallest multiple – Project Euler Solution
6 Sum square difference – Project Euler Solution
7 10001st prime – Project Euler Soution
8 Sieve of Eratosthenes
9 Bubble Sort Implementation in Python
10 How to Solve Linear Equations with Matrix Inversion
暂无评论内容