Problem 9
Problem 9
# Problem_9.py
"""
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
pow(a, 2) + pow(b, 2) = pow(c, 2)
For example, pow(3, 2) + pow(4, 2) = 9 + 16 = 25 = pow(5, 2).
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
找出满足a + b + c = 1000的毕达哥拉斯三元数组(Pythagorean triplet)
找出三数之积
"""
import math ans = []
for a in range(1, 1000):
for b in range(a, 1000):
power = pow(a, 2) + pow(b, 2)
c = math.sqrt(power)
if c % int(c) != 0.0:
continue
c = int(c)
print(a, b, c, a+b+c)
if a+b+c == 1000:
ans.extend([a, b, c])
break print(ans)
tot = 1
for i in ans:
tot *= i
print(tot)
Problem 9的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
$s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...
随机推荐
- Python学习-修饰器 - itemgetter的妙用
下面这篇对装饰器讲的很好,懂了. http://python.jobbole.com/85056/ <简单 12 步理解 Python 装饰器> 使用装饰器非常简单(见步骤10),但是写装 ...
- [React] Update State Based on Props using the Lifecycle Hook getDerivedStateFromProps in React16.3
getDerivedStateFromProps is lifecycle hook introduced with React 16.3 and intended as a replacement ...
- LINQ查询知识总结
-------适合自己的才是最好的!!! LINQ查询知识总结:案例分析 案例:汽车表car,系列表brand,厂商表productor private MyCarDataContext _Cont ...
- ssh无法连接到远端Ubuntu的解决方法
近日,饱受无法远程登录到新安装在VMWare上的Ubuntu虚拟机,现在发现问题所在.故记录此问题的解决方式,以备后用. 一.远程登录虚拟机的准备: Ubuntu虚拟机的联网方式应该选择Bridged ...
- Myeclipse快捷键备忘
1.编辑类 Ctrl+定义好的类名 链接到你定义好的类的窗口 Ctrl + / 为选中的一段代码加上或去掉注释符 // (必须选中代码块) Ctrl ...
- spring中使用HibernateTemplate或HibernateDaoSupport报类型转换错误
使用spring的HibernateDaoSupport的时候.报错例如以下: java.lang.ClassCastException: java.lang.String cannot be cas ...
- h5-7 canvas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ubuntu16.04安装chrome谷歌浏览器
按下 Ctrl + Alt + t 键盘组合键,启动终端. 输入以下命令: sudo wget http://www.linuxidc.com/files/repo/google-chrome.lis ...
- Node.js:目录
ylbtech-Node.js:目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 1. http://www.runoob.com/nodejs/nodejs ...
- BZOJ-4706 B君的多边形 OEIS
题面 题意:有一个正n多边形,我们要连接一些对角线,把这个多边形分成若干个区域,要求连接的对角线不能相交,每个点可以连出也可以不连出对角线,即最终不要求所有区域均为三角形,问总方案数mod (10^9 ...