首页 > 代码库 > projecteuler---->problem=6----Sum square difference
projecteuler---->problem=6----Sum square difference
title:
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 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.
前十个正整数的平方和是:12 + 22 + ... + 102 = 385
前十个正整数的和的平方是:(1 + 2 + ... + 10)2 = 552 = 3025
因此前十个正整数的和的平方,与前十个正数整数的平方和,的差是2640。
现在请你求出前一百个正整数的和的平方与前一百个正整数的平方和的差。
解答:
a,b=0,0 m=100 for i in range(1,m+1): a += pow(i,2) b = pow((1+m)*m/2,2) print b-a
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。