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 ...
随机推荐
- ue4 fstring 和std::string互转
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/6517-convert-std-strin ...
- Wndows下Apache+php+Mysql环境的搭建及其涉及的知识
一.安装Apache 1. 在网上搜索以下3个文件,以及找一个地方新建一个文件夹 好吧,这里有下载链接:http://pan.baidu.com/s/1hr9IdSS 文件夹内有:apache,mys ...
- Django 的逆向解析url(转)
Django中提供了一个关于URL的映射的解决方案,你可以做两个方向的使用: 1.有客户端的浏览器发起一个url请求,Django根据URL解析,把url中的参数捕获,调用相应的试图, 获取相应的数据 ...
- Excel柱状图折线图组合怎么做 Excel百分比趋势图制作教程
Excel柱状图折线图组合怎么做 Excel百分比趋势图制作教程 用excel作图时候经常会碰到做柱状图和折线图组合,这样的图一般难在折线图的数据很小,是百分比趋势图,所以经常相对前面主数据太小了,在 ...
- NFS客户端挂载目录后无写入权限的解决方案
转载至:https://blog.csdn.net/younger_china/article/details/52089337 在客户机通过 mount -o rw -t nfs 192.168.1 ...
- Codeforces Beta Round #77 (Div. 2 Only) A. Football【字符串/判断是否存在连续7个0或7个1】
A. Football time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 前端与编译原理——用JS写一个JS解释器
说起编译原理,印象往往只停留在本科时那些枯燥的课程和晦涩的概念.作为前端开发者,编译原理似乎离我们很远,对它的理解很可能仅仅局限于"抽象语法树(AST)".但这仅仅是个开头而已.编 ...
- 为Array对象添加一个去除重复项的方法
输入例子 [false, true, undefined, null, NaN, 0, 1, {}, {}, 'a', 'a', NaN].uniq() 输出例子 [false, true, unde ...
- Python数据分析与展示[第一周]
ipython 中的问号 获得相关的描述信息 %run 系统文件 执行某一个文件 ipython的模式命令 %magic 显示所有的魔术命令 %hist 命令历史输入信息 %pdb 异常发 ...
- FastAdmin 安装后点登录没有反应怎么办?
FastAdmin 安装后点登录没有反应怎么办? 很多小伙伴安装后点"登录"没有反应. 这个 URL 是对的,但是页面就是不改变. 如果这时候点击 URL 变了,那没有到登陆界面, ...