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 ...
随机推荐
- xml中不能直接添加ViewGroup
我知道可以直接添加一个<View />的,今天想添加个容器类,然后后台动态添加SurfaceView到ViewGroup容器里,不过提示inflate报错了.难道ViewGroup不能直接 ...
- 利用golang语法检查对象是否实现了接口
var _ ipc.Server = &CenterServer{} CenterServer是否实现了 ipc.Server的接口.编译期间检测,这是很好的编程实践. 稍后详述...
- Guava Collect
Guava是什么 进入新公司就会接触一些新的东东,Guava就是一个,Guava是Google的一个开源类库,丰富了JDK的API,并且使用起来非常方便,本文介绍的是Guava collect包下的一 ...
- Node.js初体验
1.Node.js是什么 [1]Node是一个server端 JavaScript 解释器,但是真的以为JavaScript不错的同学学习Node就能轻松拿下,那么你就错了.总结:水深不深我还不知道, ...
- JAVA 多线程同步与互斥
1. 为什么需要互斥: 互斥操作 保证了 多线程操作的 原子性 , java的 互斥 语义 有 synchronized 关键字 提供. 主要方式 有 同步代码块 和 同步方法 两种 2. ...
- python Sina微博自动转发带抽奖字样的微博,添加关注,取消关注
项目地址:https://github.com/chengshuyi/SinaWeibo 具有的功能 转发带抽奖字样的微博并可以@相应数量的好友 提取关注并添加关注 取消关注 获取粉丝列表
- 启动android程序报错
提示错误如下: The connection to adb is down, and a severe error has occured. [2010-03-11 09:36:56 - HelloO ...
- 使用Application_Error捕获站点错误并写日志
Global.ascx页面使用以下方法即可捕获应用层没有try cath的错误 protected void Application_Error(Object sender, EventArgs e) ...
- Android Studio 打开弹出警告框
1.Android Studio打开后,自己的项目没有打开,就弹出了警告框,重启之后依然弹出警告框: 警告框内容:"Cannot load project: java.lang.Illega ...
- 让 IE 支持HTML5 placeholder
HTML5 新增的placeholder属性已经得到现代浏览器的支持,旨在提供简单的API可以为文本输入框设置 描述输入字段预期值的提示信息(hint). 这是W3C在标准化的过程中对用户体验的更多考 ...