Porject Euler Problem 6-Sum square difference
我的做法就是暴力,1+...+n 用前n项和公式就行
12+22+....+n^2就暴力了
做完后在讨论版发现两个有趣的东西。
一个是 (1+2+3+...+n)2=(13)+(23)+(33)+...+(n^3)
另一个是 12+22+....+n^2的公式以及推导。
假设f(n) = an3 + bn2 + cn + d
已知:f(0) = 0; f(1) = 1; f(2) = 5; f(3) = 14
然后带入解方程,得到a,b,c,d,再用归纳法证明其正确性。
证明过程在给出的题解中。
公式:1^2 + 2^2 + ... + n^2 = n * (n+1) * (2n+1) * 1/6
天知道他是怎么想到把方程假设成那样的。不过百度搜搜也有推导。
a = 5050*5050
b = 0
for x in range(1,100+1):
b += x*x
print a-b
Porject Euler Problem 6-Sum square difference的更多相关文章
- Problem 6: 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 ...
- Sum square difference
简单: e sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square o ...
- projecteuler 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 ...
- (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 Problem 18-Maximum path sum I & 67-Maximum path sum II
基础的动态规划...数塔取数问题. 状态转移方程: dp[i][j] = num[i][j] + max(dp[i+1][j],dp[i+1][j+1]);
- Project Euler Problem 16-Power digit sum
直接python搞过.没啥好办法.看了下别人做的,多数也是大数乘法搞过. 如果用大数做的话,c++写的话,fft优化大数乘法,然后快速幂一下就好了.
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
随机推荐
- 洛谷P1082 同余方程 [2012NOIP提高组D2T1] [2017年6月计划 数论06]
P1082 同余方程 题目描述 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开. 输出格式: 输 ...
- 【logo】设计书籍的logo
一个女孩发光般的看着,眼前发现的书籍 含义:这本书就是女孩想要得到的书籍 平台的宗旨:就是让学生能够得到想要的书籍 书籍来源:其他学生的书籍 目的:实现书籍回收再利用,同时让接受者低于市场价得到
- C++多态小结
C++ 多态 多态 多态按字面的意思就是多种形态.当类之间存在层次结构,并且类之间是通过继承关联时,就会用到多态. C++ 多态意味着调用成员函数时,会根据调用函数的对象的类型来执行不同的函数. 多态 ...
- 【python小随笔】celery周期任务(简单原理)
1:目录结构 |--celery_task |--celery.py # 执行任务的main函数 |--task_one # 第一个任务 |--task_two # 第2个任务 . . . . |-- ...
- pycharm 2017 序列号失效问题解决(2016-2017版本都有效)
pycharm 序列号失效问题解决 this license BIG3CLIK6F has been cancelled 具体如下: 对,没错,这个激活码本来可以使用到2018年的,但是,忽然间 ...
- Directx11教程36 纹理映射(6)
原文:Directx11教程36 纹理映射(6) 本章主要是整理代码,做以下两件事情: 1.把世界坐标矩阵的计算,放在GraphicsClass的渲染函数中,之前放在D3DClass中,而且只是 ...
- 实现自定义docker 镜像共享
我觉得docker最大的便利性体现在可以实现镜像共享,方便团队在同一环境下开发.当然docker的强大之处不止于此. 接下来我用一个例子来演示如何进行docker镜像共享,步骤如下(Ubuntu): ...
- SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作)
SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作) 2012-12-21 未来决定... http://www.ebama.net/thread-107643-1-1.html ...
- 【JZOJ4835】【GDOI2017模拟10.31】量化交易
题目描述 数据范围 解法 贪心: 从左往右枚举,设枚举到元素为x,并维护一个堆: 设此时堆顶元素为y, 如果x大于y,那么x可以与y产生差价,立即将差价贡献给答案. 如果y之前已经和其他元素z产生过差 ...
- Linux下如何切换用户
切换用户的命令为:su username 从普通用户切换到root用户,还可以使用命令:sudo su 在终端输入exit或logout或使用快捷方式ctrl+d,可以退回到原来用户,其实ctrl+d ...