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 ...
随机推荐
- python枚举详解
1. 枚举的定义 首先,定义枚举要导入enum模块. 枚举定义用class关键字,继承Enum类. 用于定义枚举的class和定义类的class是有区别[下一篇博文继续分享]. 示例代码: from ...
- Sublime Text Version 3.2.1(Build 3207)注册
Sublime Text Version 3.2.1, Build 3207 一. host添加地址 C:\Windows\System32\drivers\etc\hosts 127.0.0.1 l ...
- Java IO:为什么InputStream只能读一次
http://zhangbo-peipei-163-com.iteye.com/blog/2021879 InputStream的接口规范就是这么设计的. /** * Reads the next b ...
- Django项目:CRM(客户关系管理系统)--02--01PerfectCRM基本配置ADMIN02
三.CRM项目表结构设计 from django.db import models # Create your models here. """ #运行 Terminal ...
- Javascript面向对象编程(四):非构造函数的继承
什么叫非构造函数的继承? 比如,现在有一个对象,叫做"中国人". var Chinese = { nation:'中国' }; 还有一个对象,叫做"医生". v ...
- vue渲染学生信息
渲染学生信息 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- Congratulation!顺利通过-2019年6月份的PMP考试
祝贺邮件 证书
- 算法复杂度表示(大O表示法)
- 概念: 大O表示法:称一个函数g(n)是O(f(n)),当且仅当存在常数c>0和n0>=1,对一切n>n0均有|g(n)|<=c|f(n)|成立,也称函数g(n)以 ...
- 【水滴石穿】bstmy-blend-app
这个项目是一个简单的底部导航切换页面 项目的地址为:https://github.com/Bstmy/bstmy-blend-app 先看效果 点击首页是首页面,点击个人中心是个人中心页面 先看代码 ...
- 【风马一族_php】数组函数
原文来自:http://www.cnblogs.com/sows/p/6045699.html (博客园的)风马一族 侵犯版本,后果自负 2016-11-09 15:56:26 数组 函数 php- ...