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 ...
随机推荐
- SWT中嵌入Swing的JTextFeild却不能编辑
SWT中嵌入Swing的JTextFeild却不能编辑 学习了:http://www.iteye.com/problems/49487 膜拜一下 org 竟然有这样的坑,需要在中间添加一个JApp ...
- C语言可变參实现參数累加返回
C语言可变參的作用真的是很大,自从发表了可变參怎样实现printf.fprintf,sprintf的文章以来.便有不少博友私信问我实现的机制,我也解释了相关的知识点.今天,我们借着这个机会,再来举一个 ...
- 扩展欧几里德 poj1061 青蛙的约会
扩展欧几里德很经典.可是也有时候挺难用的.一些东西一下子想不明确.. 于是来了一个逆天模板..仅仅要能列出Ax+By=C.就能解出x>=bound的一组解了~ LL exgcd(LL a, LL ...
- HDU4300-Clairewd’s message-KMP
题目链接:pid=4300">http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目意思真的非常难读懂. 题意:给定两组字符串,第一组仅仅有 ...
- luogu4011 孤岛营救问题 分层图
关键词:分层图 状态压缩 最短路径 分层图:现在要求从起点到终点的最优路线,但受到手里拿着哪些钥匙的影响,最优路线不单纯了.因此,决定一个节点.一条边的存在的数中应当增加一个手中拿有钥匙的状态.这样就 ...
- oc5--方法
// main.m // 第一个OC类-方法2 #import <Foundation/Foundation.h> // 1.编写类的声明 @interface Iphone : NSOb ...
- 国内物联网平台初探(一) ——百度物接入IoT Hub
物接入IoT Hub - 架构 全托管的云服务,帮助建立设备与云端之间安全可靠的双向连接 支撑海量设备的数据收集.监控.故障预测等各种物联网场景 物接入IoT Hub - 功能 通信协议:支持MQTT ...
- nyoj--127--星际之门(一)(生成树的数量)
星际之门(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门,它 ...
- 找新朋友(hdoj--1286--欧拉函数)
欢迎参加--每周六晚的BestCoder(有米!) 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- [源码管理] ubuntu下SVN服务器安装配置
一.SVN安装1.安装包$ sudo apt-get install subversion2.添加svn管理用户及subversion组$ sudo adduser svnuser$ sudo add ...