码迷,mamicode.com
首页 > 其他好文 > 详细

projecteuler---->problem=6----Sum square difference

时间:2014-06-05 12:03:29      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:python

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 bubuko.com,布布扣 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


projecteuler---->problem=6----Sum square difference,布布扣,bubuko.com

projecteuler---->problem=6----Sum square difference

标签:python

原文地址:http://blog.csdn.net/china_zoujinyong/article/details/27351419

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!