Project Euler # 6 "Difference in sum of squares" in Python

Problem 6 "Difference in sum of squares"

For the first 10 natural numbers, the sum of their squares is

1^2 + 2^2 + ... + 10^2 = 385

For the first 10 natural numbers, the square of their sum is

(1 + 2 + ... + 10)^2 = 3025

The difference between these numbers is 3025-385 = 2640. Similarly, find the difference between the sum of squares and the square of the sum for the first 100 natural numbers.

Python


n = 100

seq = range(1, n+1)

result = sum(seq)**2 - sum(map(lambda x: x**2, seq))

print result
print result == 25164150

result


25164150
True

Recommended Posts

Project Euler # 6 "Difference in sum of squares" in Python
Project Euler # 16 "Sum of Powers" in Python
Project Euler # 10 "sum of prime numbers" in Python
Project Euler # 17 "Number of Characters" in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Functional programming in Python Project Euler 1
Project Euler 10 "Sum of Prime Numbers"
[Note] Project Euler in Python (Problem 1-22)
Functional programming in Python Project Euler 3
Project Euler # 5 "Minimum Multiples" in Python
Functional programming in Python Project Euler 2
Project Euler # 15 "Lattice Path" in Python
Project Euler # 4 "Maximum Palindrome" in Python
Project Euler # 3 "Maximum Prime Factors" in Python
Project Euler # 11 "Maximum Product in Grid" in Python
Project Euler # 9 "Special Pythagorean Triple" in Python
Project Euler # 14 "Longest Collatz Sequence" in Python
Project Euler # 2 "Even Fibonacci Numbers" in Python
Project Euler # 8 "Maximum Product in Number String" in Python
Project Euler # 12 "High Divisibility Triangular Number" in Python
Implement sum in Python
Difference between Ruby and Python in terms of variables
[python] Calculation of months and years of difference in datetime
Find the difference in Python
Learn cumulative sum in Python
Equivalence of objects in Python
Implementation of quicksort in Python
What I learned by solving 30 questions of python Project Euler
Pixel manipulation of images in Python
Difference between list () and [] in Python
Difference between == and is in python
Division of timedelta in Python 2.7 series
MySQL-automatic escape of parameters in python
Handling of JSON files in Python
Implementation of life game in Python
Waveform display of audio in Python
Create Python project documentation in Sphinx
Law of large numbers in python
Implementation of original sorting in Python
Project Euler 11 "Maximum product in grid"
Reversible scrambling of integers in Python
Project Euler 9 Retention of calculation results
Difference in behavior of transparent Frame made with tkinter in pyinstaller [Python]
Conversion of string <-> date (date, datetime) in Python
Project Euler 37
Project Euler 47
Project Euler 31
Check the behavior of destructor in Python
Project Euler 4
Project Euler 38
(Bad) practice of using this in Python
Do a non-recursive Euler Tour in Python
General Theory of Relativity in Python: Introduction
difference between statements (statements) and expressions (expressions) in Python
Project Euler 26
Project Euler 8
Output tree structure of files in Python
Display a list of alphabets in Python 3
Project Euler 22
Project Euler 19
Project Euler 50