Special Pythagorean triplet

Problem 9

A Pythagorean triplet is a set of three natural numbers, a  b  c, for which,

a2 + b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

 
The code is simple:
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的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  4. 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 ...

  5. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  6. 【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 × ...

  7. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  9. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. C# 面向对象的封装、继承、多态

    一.封装: 封装:把客观的事物封装成类,使用和修改方便: 作用和结构体使用方法相似,程序执行流程不同: 要点:成员变量,属性,成员方法,构造函数,成员方法的静态和非静态,命名空间,常用的访问修饰符pu ...

  2. Python协程笔记 - yield

    生成器(yield)作为协程 yield实际上是生成器,在python 2.5中,为生成器增加了.send(value)方法.这样调用者可以使用send方法对生成器发送数据,发送的数据在生成器中会赋值 ...

  3. 使用pycharm开发代码上传到GitLab和GitHub

    使用pycharm开发代码上传到GitLab和GitHub 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我这里主要是针对局域网的自减的GitLab服务器,python开发工程师如 ...

  4. Python基础【day02】:数据运算(二)

    本节内容 数据运算 表达式while 循环 一.数据运算 算数运算: 比较运算: 赋值运算: 逻辑运算: 成员运算: 身份运算: 位运算: #!/usr/bin/python a = 60 # 60 ...

  5. CodeForces - 327D Block Tower

    D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  6. Java Web之路(五)JSP

    一.jsp的3个指令 JSP指令(directive)是为JSP引擎而设计的,它们并不直接产生任何可见输出,而只是告诉引擎如何处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指令: p ...

  7. luogu 1030 求先序遍历

    此题给出中序遍历和后序遍历后的序列,乍一看确乎想不出法子解决,毕竟是逆向思维: 但是后序遍历的特殊性质 son1,son2,x 使得后序的末尾便是根节点,再由中序天然的递归性质便可递归输出,用下fin ...

  8. Nginx 中 FastCGI 配置示例

    nginx 中 FastCGI 参数:主要是在 http 层 :保证PHP环境的高校运行 主要对PHP用来解析 fastcgi_cache_path /tmp/fastcgi_cache levels ...

  9. 数据库之MySQL存储过程

    一.参考文献 https://www.oschina.net/translate/create-and-call-mysql-stored-procedure-database-sql-example ...

  10. 第18月第10天 iOS11 uicollectionview

    1. - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollect ...