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 ...
随机推荐
- 洛谷P1263 宫廷守卫
P1263 宫廷守卫 题目描述 从前有一个王国,这个王国的城堡是一个矩形,被分为M×N个方格.一些方格是墙,而另一些是空地.这个王国的国王在城堡里设了一些陷阱,每个陷阱占据一块空地. 一天,国王决定在 ...
- 【CodeVS】【2004年NOIP全国联赛提高组】1057 津津的储蓄计划
1057 津津的储蓄计划 2004年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题目描述 Description 津津的零花钱一直都是 ...
- Leetcode47. Permutations II全排列2
给定一个可包含重复数字的序列,返回所有不重复的全排列. 示例: 输入: [1,1,2] 输出: [ [1,1,2], [1,2,1], [2,1,1] ] 在全排列1题目的基础上先排序,目的是把相同的 ...
- JZOJ 平衡的子集
Description 夏令营有N个人,每个人的力气为M(i).请大家从这N个人中选出若干人,如果这些人可以分成两组且两组力气之和完全相等,则称为一个合法的选法,问有多少种合法的选法? Input 第 ...
- Ajax.dll使用方法和步骤(比较方便的实现ajax)
转载自 博客频道 - CSDN.NET http://blog.csdn.net/houhanxin1/article/details/6671470 1. 有直接用框架的:Ajaxpro和Aja ...
- oracle触发器级联删除
create or replace trigger delete_trigger1 after delete on contracting_party for each row begin if de ...
- 找不到windows.h源文件
一.找不到源文件window.h 今天在网上下了个程序,在公司用VS2015能打开,在家用VS2017却打不开,提示找不到源文件window.h,因为引用了这个头文件,但是却找不到 解决方案: 右侧解 ...
- Python 模块chardet安装过程(windows环境)
最近需要一个txt文件的批量转码功能,在网上找到一段批量处理java源文件的py程序如下: #-*- coding: utf-8 -*- import codecs import os import ...
- 【md5加密】不可逆之简单例子原理
import hashlib def md5_get(data): ret = hashlib.md5("gfdwuqmo@md1.".encode("utf-8&quo ...
- Directx11教程(14) D3D11管线(3)
原文:Directx11教程(14) D3D11管线(3) 现在我们开始学习一些CP(command processor)的知识.参考资料: http://fgiesen.wordpres ...