Project Euler Problem6
Sum square difference
Problem 6
The sum of the squares of the first ten natural numbers is,
The square of the sum of the first ten natural numbers is,
Hence 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.
Quite simple , the code is as follows:
def getSumOfSquare(began,end):
sum = 0
for i in range(began, end+1):
sum += pow(i, 2)
return sum def getSquareOfSum(began, end):
sum = 0
for i in range(began, end+1):
sum += i
sum = pow(sum, 2)
return sum print(getSumOfSquare(1, 100))
print(getSquareOfSum(1, 100))
print(getSquareOfSum(1, 100)-getSumOfSquare(1, 100))
Project Euler Problem6的更多相关文章
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Project Euler 9
题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...
- 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 ...
- project euler 169
project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...
- 【Project Euler 8】Largest product in a series
题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...
- Project Euler 第一题效率分析
Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...
- Python练习题 049:Project Euler 022:姓名分值
本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...
- Python练习题 048:Project Euler 021:10000以内所有亲和数之和
本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...
随机推荐
- C# try catch语句&获取随机数的方法
try catch语句: try{ //无论如何都会走,必须写: } catch(Exception a){ //Exception报异常,需要定义,需要写输出语句: //如果上面执行失败走,必须写: ...
- poj 2763(RMQ+BIT\树链剖分)
传送门:Problem 2763 https://www.cnblogs.com/violet-acmer/p/9686774.html 题意: 一对夫妇居住在xx村庄,小屋之间有双向可达的道路,不会 ...
- 集合总结(全是代码)----------java基础学习
前言:在刚学习的时候,切记不能粘贴复制,更不能眼高手低,再简单的代码,都要自己独立动手写. 第一步:目录结构 第二步:代码区 Student.java:(一个学生的实体类) package com.m ...
- mac 本上对 rar 压缩包解压
以前从晚上各种找软件对 xxx.rar 压缩包文件进行解压,也确实找到过那么几个,要不是不好用就是解压完有乱码,很是头疼. 这次又遇到这样的问题,于是下定决心将这个问题彻底解决好,经过验证,总结一下最 ...
- grafana-zabbix部署和使用
grafana-zabbix安装 官网安装介绍地址:https://grafana.com/plugins/alexanderzobnin-zabbix-app/installation 下载地址:h ...
- 学习windows编程 day5 之 区域裁剪
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...
- 关于spring事务
https://www.cnblogs.com/caoyc/p/5632963.html 这一篇博客讲的很清楚,一些参数和事务的概念 在serveice层中 每个方法都要写上关于事务的注解.这两个 ...
- .NET MVC中的防CSRF攻击
一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSR ...
- 通用Excel文件导出工具类
1:Excel格式 2:ExcelUtil.java import java.io.ByteArrayOutputStream; import java.io.IOException; import ...
- 08-DML(插入、更新、删除)
1. 插入 (1). 插入完整数据记录 (2). 插入数据记录的一部分 (3). 插入多条记录(MySQL特有的) INSERT INTO table_name (column1,column2,co ...