Project Euler Problem9
Special Pythagorean triplet
Problem 9
A Pythagorean triplet is a set of three natural numbers, a
b
c, for which,
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
a = 0
b = 0
c = 0
totalSum = 1000
cMax = int(totalSum/2)
cMin = int(totalSum/3)
aMax = cMin
c = cMax
while c > cMin:
b = c - 1
while b > 1:
a = totalSum - c - b
if a > b or a < 1 or a > aMax:
break
if a*a + b*b == c*c:
print(a, b, c)
print(a*b*c)
break
b -= 1
c -= 1
Project Euler Problem9的更多相关文章
- [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 ...
随机推荐
- pyinstaller模块使用
目前pip install pyinstaller已经成熟 但是还是有一些坑,郁闷了好久,记一下注意点吧. 将py脚本打包成exe文件时,如果导入了非python自带库,则需要将导入的库从site-p ...
- SPI、I2C、UART三种串行总线协议的区别
第一个区别当然是名字: SPI(Serial Peripheral Interface:串行外设接口); I2C(INTER IC BUS) UART(Universal Asynchronous R ...
- TextView 借助Linkify,使用自定义模式设置链接
http://my.oschina.net/fengheju/blog/176105 TextView是android中的一个比较常用的控件,它有一个非常有趣的特性,可以通过android:autoL ...
- ASP 运行结果显示空白 --- 是编码的原因。
比如有一个 a.asp 文件编码: utf-8 在a.asp代码中有一行:<!--#include file="b.asp"--> 但是 b.asp 文件编码是 gb2 ...
- gb2312提交的url编码转换成utf8的查询
使用场景,当一网站是gb2312的编码向另一个是utf8的网站提交查询 如:http://search.chinayq.com/?key=%C0%D6%C6%F7 其中key为gb2312的url编码 ...
- 学习Git笔记
一.名词解释 1.仓库(Repository) 仓库用来存放项目代码,每个项目对应一个仓库,多个开源项目则有多个仓库. 2.收藏(Star) 收藏项目,方便下次查看 3.复制克隆项目(Fork) 该f ...
- JavaEE学习总结(十四)— 人工智能微博
一.数据库与表 人工智能微博(blog) note(id,bt,nr);微博信息(编号,标题,内容) 列表添加 数据库脚本 /* Navicat MySQL Data Transfer Source ...
- 多线程ExecutorService中submit和execute区别
submit和execute都是 ExecutorService 的方法,都是添加线程到线程池中. 区别 三个区别: 1.接收的参数不一样 2.submit有返回值,而execute没有 Method ...
- HDU - 4333 Revolving Digits(扩展KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意 一个数字,依次将第一位放到最后一位,问小于本身的数的个数及等于本身的个数和大于本身的个数,但是要注意 ...
- Js/Jquery 关闭 离开或刷新当前页面时提醒,和执行解绑取消提醒
如图,现在的 cnblogs 或者QQ邮箱编辑页面,刷新.关闭提醒: <script src="../../Common/Js/jquery-1.8.1.min.js"> ...