For the first 10 natural numbers, the sum of their squares is
12 + 22 + ... + 102 = 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.
In the same way, find the difference between the sum of squares and the square of the sum for the first 100 natural numbers. http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%206
Implemented as follows using the arithmetic progression sum formula and the square number sum formula. https://www.shinko-keirin.co.jp/keirinkan/kosu/mathematics/kirinuki/kirinuki16.html http://www2.ocn.ne.jp/~mizuryu/jyugyo/heihou.html
import mymath
def cof():
(s,l,diff) = (1,100,1)
ans = (mymath.sum_nums(s,l,diff)**2) - mymath.sum_squars(l)
print ans
if __name__ == '__main__':
cof()
About mymath below http://qiita.com/cof/items/45d3823c3d71e7e22920
Recommended Posts