Problem 6: Sum square difference
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025Hence 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.
这第六题python实现最简单吧
max1 = 100 sum1 = 0
sum2 = 0
for i in range(1,max1+1):
sum1 += i**2 sum2 = ((1+max1)*max1/2)**2
print(sum2-sum1)
Problem 6: Sum square difference的更多相关文章
- (Problem 6)Sum square difference
Hence the difference between the sum of the squares of the first ten natural numbers and the square ...
- projecteuler Sum square difference
The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...
- Sum square difference
简单: e sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square o ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- 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 ...
- [LeetCode&Python] Problem 404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...
- [LeetCode&Python] Problem 530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- [LeetCode&Python] Problem 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
随机推荐
- CI框架简单使用
CodeIgniter框架 1.回忆MVC 1.1.M:模型,提供数据,保存数据 1.2.V:视图,只负责显示,表单form 1.3.C:控制器,协调模型和视图 1.4.action:动作,是控制器中 ...
- Vue-admin工作整理(十九):从数字渐变组件谈第三方JS库Count-to的使用
1.组件封装基础 npm install countup@latest 2.组件中使用id值 3.组件中获得dom 如何封装一个组件,在组件中用到需要传入HTML元素ID值的JS库时如何处理,如何获取 ...
- Apache和Nginx的区别
Nginx 轻量级,采用 C 进行编写,同样的 web 服务,会占用更少的内存及资源 抗并发,nginx 以 epoll and kqueue 作为开发模型,处理请求是异步非阻塞的,负载能力比 apa ...
- (23)socket多进程并发
# 对于服务器自己本身,一个程序只能绑定一个端口 # 同一个端口可以多个客户端来连接, # 只要server_ip+ server_port +client_ip + cilent_port 不一样, ...
- 关于index.html被缓存问题
关于web的缓存策略,推荐这篇文章:点击 在开发时候经常遇到一个问题,我们根据版本号去控制缓存问题,当我们发布新版本,使用心得版本号的时候,发现html里面引用的版本号却是旧的版本号 ,原来是该htm ...
- 大数据分析-excel常用技巧
在用EXCEL制表时,经常要要用到填充,比如1到100行内容相同或引用公式,大多数人会用鼠标拖来拖去,例如: 在第一行的A1单元格右下方 鼠标指针 变 实心黑十字 向下拉或向右,向左拉 我想拉100行 ...
- ArcGIS中删除“点”附带的对应“文本信息”
现状: 用ArcMap打开对应的.mxd文件,导入KML数据后,几何类型“点” - 每一个点都附带对应的文本信息“Placemark”,如下图: 问题:ArcGIS中如何 删除“点”附带的对应“文本信 ...
- python3 LDA主题模型以及TFIDF实现
import codecs #主题模型 from gensim import corpora from gensim.models import LdaModel from gensim import ...
- SQL运行优化收藏
如何让你的SQL运行得更快(转贴) ---- 人们在使用SQL时往往会陷入一个误区,即太关注于所得的结果是否正确,而忽略了不同的实现方法之间可能存在的性能差异,这种性能差异在大型的或是复杂的数据库环境 ...
- JAVA写接口傻瓜($)教程(三)
接上一篇 补充:事实上java的类需要在src文件夹里写,classes文件夹只是会同步src文件夹里的类.如果在classes文件夹里操作java类,是会提示文件只读的.src文件夹中进行代码编写 ...