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 ...
随机推荐
- android 百度地图 定位获取位置失败 62错误
一切正常步骤进行但是还是没有获得定位,得到的坐标总是49E.xxxx,错误代码总是62 总是以为代码.或jar包.或还有什么权限没给.搞了好久,十分郁闷.在控制台上又没有什么具体的错误提示 经过无数次 ...
- 简单理解epel源
EPEL源-是什么全称 EPEL源 EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适 ...
- Effective java 系列之异常转译
异常转译:当位于最上层的子系统不需要关心底层的异常细节时,常见的作法时捕获原始异常,把它转换一个新的不同类型的异常,在将新异常抛出. 通常方法捕获底层异常,然后抛高层异常. public static ...
- selenium、UA池、ip池、scrapy-redis的综合应用案例
案例: 网易新闻的爬取: https://news.163.com/ 爬取的内容为一下4大板块中的新闻内容 爬取: 特点: 动态加载数据 ,用 selenium 爬虫 1. 创建项目 scrapy ...
- 创建ajax的步骤
第1步:创建XMLHttpRequest对象,也就是创建一个异步调用对象. 第2步:创建一个新的HTTP请求,并指定该HTTP请求的方法.URL以及验证信息. 第3步:设置响应HTTP状态变化的函数. ...
- java Comparable and Comparator
1.Comparable简介 此接口对实现它的每个类的对象强加一个总排序.这种排序被称为类的自然排序,类的compareTo方法被称为其自然比较方法.可以通过 Collections.sort(和Ar ...
- Angular7.1.4+Typescript3.1框架学习(一)
起因:学习ionic4之前先学习下angular+ts 以win10为开发平台:当前最新版本为angular7;根据官网资料做如下总结: 1. angular安装 前提:Node.js 的 8.x 或 ...
- zzw原创_mysql脚本打印出提示信息
批量执行大量数据库脚本的时候,数据库脚本报错,要定位到哪个脚本,如果数据库脚本中不主动打印脚本信息比较困难 一.ORACLE 在oracle数据库脚本,可以借助prompt比如脚本中放如下语句: pr ...
- 使用Github Composer Packagist编写及发布扩展包
1.在github中创建自己的仓库,然后本地clone,初始化composer init ,在composer.json中增加autoload "autoload": { &quo ...
- play framework 笔记
@main("Hello")调用 main.scala.hmtl,页面名称 Hello conf/routes 文件定义了映射规则 参数的传递入口在 controller 的方法中 ...