Python练习题 034:Project Euler 006:和平方与平方和之差
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6
# Project Euler: Problem 6: Sum square difference
# The sum of the squares of the first ten natural numbers is,
# 1**2 + 2**2 + ... + 10**2 = 385
# The square of the sum of the first ten natural numbers is,
# (1 + 2 + ... + 10)**2 = 552 = 3025
# 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.
# Answer: 25164150 x = y = 0
for i in range(1, 101):
x += i
y += i**2
print(x**2 - y)
这题纯粹是送分题,就是简单的加减法和乘方计算。应该没啥算法可言吧。。。
Python练习题 034:Project Euler 006:和平方与平方和之差的更多相关文章
- Python练习题 032:Project Euler 004:最大的回文积
本题来自 Project Euler 第4题:https://projecteuler.net/problem=4 # Project Euler: Problem 4: Largest palind ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Python练习题 046:Project Euler 019:每月1日是星期天
本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- Python练习题 033:Project Euler 005:最小公倍数
本题来自 Project Euler 第5题:https://projecteuler.net/problem=5 # Project Euler: Problem 5: Smallest multi ...
- 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 ...
- Python练习题 047:Project Euler 020:阶乘结果各数字之和
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...
- Python练习题 045:Project Euler 017:数字英文表达的字符数累加
本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...
随机推荐
- typepra快捷键
- Java Android程序员软件开发知识:枚举的介绍,以及代码的编写教程。
Java枚举 Java 5.0引入了枚举,枚举限制变量只能是预先设定好的值.使用枚举可以减少代码中的bug. 例如,我们为果汁店设计一个程序,它将限制果汁为小杯.中杯.大杯.这就意味着它不允许顾客点除 ...
- xml selectnodes
[xML ]SelectNodes的用法 之前简单找个SelectNodes的例子看了看,写了读取XML文件节点的程序,但是节点数目有限制,后来仔细看看,是自己没完全弄清SelectNodes的用法, ...
- 使用Unity的50个建议
关于这些建议 这些建议并不适用于所有的项目 这些建议是基于我与3-20人的小团队项目经验总结出来的 结构.可重复使用性.明晰度都是有价的——团队规模和项目规模决定了是否值得付这个价. 一些建议也许公然 ...
- php中的加密解密模块-mcrypt
<?php /* 打开加密算法和模式 */ $td = mcrypt_module_open('rijndael-256', '', 'ofb', ''); /* 创建初始向量,并且检测密钥长度 ...
- C# 压缩源文件(导出源文件word文件)
说明 1 : 在webUI 公共类,存放 ZipHelper 类 说明 2 :判断文件路径是否存在,不存在则创建文件夹 说明 3 : 引用类方法,判断压缩文件,返回的,是true/false 引用 ...
- 使用java8的方法引用替换硬编码
背景 想必大家在项目中都有遇到把一个列表的多个字段累加求和的情况,也就是一个列表的总计.有的童鞋问,这个不是给前端做的吗?后端不是只需要把列表返回就行了嘛...没错,我也是这样想的,但是在一场和前端的 ...
- KMP - NOI2014 动物园
单题分析:NOI2014 动物园. 题目分析:很明显题目已明确指出这是有关KMP的题,思考KMP.本题与普通KMP不同之处在于它求的是不相交最长相同前缀后缀. 如何处理不相交: 1.暴力 2. ...
- Kibana的安装
了解ELK Kibana 安装 Kibana的版本要和ES的一致 下载完毕后解压 这个解压就有点慢了 ELK的东西基本都是开箱即用的 解压后的目录 进入bin 双击启动kibana.bat 哎:启动从 ...
- 使用枚举类Enum作为callee和caller的约定,运用反射消除分支和重复代码在命令式程序中的应用
在开发过程中,程序提供的功能由简单变得复杂,承担功能的主要类也会因此变得庞大臃肿,如果不加以维护,就会散发出浓重的代码味道.下面这篇博文,主要讲述了利用Enum,反射等手段简化重构代码的过程. 代码涉 ...