Sum square difference
简单:
e sum of the squares of the first ten natural numbers is,
The square of the sum of the first ten natural numbers is,
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.
def naturalnumber(n):
sumnatural = 0
for i in xrange(1,n+1):
sumnatural += i * i
return sumnatural
def squarenumber(n):
sumsquare = 0
for i in xrange(1,n+1):
sumsquare += i
return sumsquare * sumsquare
print squarenumber(100) - naturalnumber(100)
C:\webpy\webpy\Scripts\python.exe C:/pycode/euler.py
25164150
Process finished with exit code 0
Sum square difference的更多相关文章
- projecteuler Sum square difference
The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...
- (Problem 6)Sum square difference
Hence the difference between the sum of the squares of the first ten natural numbers and the square ...
- Problem 6: Sum square difference
The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...
- Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...
- Porject Euler Problem 6-Sum square difference
我的做法就是暴力,1+...+n 用前n项和公式就行 1^2+2^2+....+n^2就暴力了 做完后在讨论版发现两个有趣的东西. 一个是 (1+2+3+...+n)^2=(1^3)+(2^3)+(3 ...
- PE 001~010
题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的 ...
- Project Euler Problem6
Sum square difference Problem 6 The sum of the squares of the first ten natural numbers is, 12 + 22 ...
- PE刷题记
PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...
- Python练习题 034:Project Euler 006:和平方与平方和之差
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...
随机推荐
- GitHub for Mac
GitHub for Mac 安装 1.从 mac.github.com 下载最新版本的 GitHub. 2.当你开启软件时,你可以选择用你的 GitHub 账户登录,或者新建一个账户. 3.在左侧, ...
- VMware Ubuntu安装详细过程
参考链接: http://blog.csdn.net/u013142781/article/details/50529030
- openssl生成自签名证书
1.生成x509格式的CA自签名证书 openssl req -new -x509 -keyout ca.key -out ca.crt 2.生成服务端的私钥(key文件)及申请证书文件csr文件 o ...
- Android Studio中解决Gradle DSL method not found: 'android()'
近期导入as的项目出了这种问题 这个问题困扰了我非常长时间,好吧,搜了半天全都是runProguard的.最后在stackoverflow上搜到解决的方法了: http://stackoverflow ...
- Robotium--takeScreenshot(截图)
在Robotium中,截图的方法时调用takeScreenshot(). 但有使用你会发现明明代码里调用了solo.takeScreenshot(),但却没有截图成功,那是因为被测试的应用没有SD卡的 ...
- Spring-----1、Spring一个简短的引论
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVrZXdhbmd6aQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- hdu1074 Doing Homework(状态压缩DP Y=Y)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Spring Remoting by HTTP Invoker Example--reference
Spring provides its own implementation of remoting service known as HttpInvoker. It can be used for ...
- DataGrid 使用模型列后实现点击列名称排序
DataGrid 使用模型列后实现点击列名称排序 代码如下: <DataGridTemplateColumn Header="型 号" SortMemberPath=&quo ...
- nyoj 623
#include <iostream> using namespace std; int main() { int a[51][51],b[51][51],c[51][51],i,j,k, ...