projecteuler Problem 9 Special Pythagorean triplet
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<b<c,形如
举个例子,32 + 42 = 9 + 16 = 25 = 52.
现在存在一个毕达哥拉斯三元数组,它满足 a + b + c = 1000.毕达哥拉斯三元数组的数值乘积。
第一次code:
public class Main { public static void main(String[] args) { System.out.println(run(1000)); } public static String run(int n) { String a=""; for(int i=1;i<n;i++) { for(int j=0;j<i;j++) { for(int s=0;s<j;s++) { if(s*s+j*j==i*i) { if(s+j+i == 1000) { a =String.valueOf(s*j*i); } } } } } return a; } }
时间效率:280毫秒。
projecteuler Problem 9 Special Pythagorean triplet的更多相关文章
- Problem 9: Special Pythagorean triplet
flag = 0 for a in range(1,1000): for b in range(a+1,1000): if a*a + b*b == (1000-a-b)**2: print(a,b) ...
- (Problem 9)Special Pythagorean triplet
A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For exampl ...
- Special Pythagorean triplet
这个比较简单,慢慢进入状态. A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = ...
- projecteuler---->problem=9----Special Pythagorean triplet
title: A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For e ...
- Project Euler Problem 9-Special Pythagorean triplet
我是俩循环暴力 看了看给的文档,英语并不好,有点懵,所以找了个中文的博客看了看:勾股数组学习小记.里面有两个学习链接和例题. import math def calc(): for i in rang ...
- projecteuler Problem 8 Largest product in a series
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = ...
- Python练习题 037:Project Euler 009:毕达哥拉斯三元组之乘积
本题来自 Project Euler 第9题:https://projecteuler.net/problem=9 # Project Euler: Problem 9: Special Pythag ...
- Project Euler Problem9
Special Pythagorean triplet Problem 9 A Pythagorean triplet is a set of three natural numbers, a b ...
- PE 001~010
题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的 ...
随机推荐
- android基础(二)Broadcast Receiver知识
1.广播的注册 (1)动态广播注册: 优点:可以灵活控制广播的注册与撤销 缺点:必须在程序启动时才能接收广播 IntentFilter :当Intent在组建之间传递时,组件想告诉android系统自 ...
- SqlServer性能优化 手工性能收集动态管理视图(三)
动态管理视图: 具体的实例语句: --关于语句执行的基本情况 select * from sys.dm_exec_query_stats --动态管理函数 需要提供参数 select top 1 ...
- Filco minila 的蛋疼。
3494左shift坏了,期间邮寄厂家维修,就把尘封多年的minila拿出来用着. 最为人诟病的问题:蓝亚适配,与mac跟iphone都能快速的匹配连接上.但是对于我的dell vestro 2012 ...
- xmind的第九天笔记
- PHP Date Function Base
/**************格式中可使用字母的含义**************/a – "am" 或是 "pm" A – "AM" 或是 ...
- Git 问题
You are not currently on a branch, so I cannot use any 症状:有一次pull的时候又出现冲突,这回用“git reset --hard FETCH ...
- C#中动态读写App.config配置文件
转自:http://blog.csdn.net/taoyinzhou/article/details/1906996 app.config 修改后,如果使用cofnigurationManager立即 ...
- redis 集群环境搭建-redis集群管理
集群架构 (1)所有的redis节点彼此互联(PING-PONG机制),内部使用二进制协议优化传输速度和带宽. (2)节点的fail是通过集群中超过半数的节点检测失效时才生效. (3)客户端与redi ...
- spl_autoload_register更改框架文件引用模式
今天单点登陆要用到 spl_autoload_register,但是YII的Yii::autoload在包含失败的时候会抛异常,就不会执行(spl_autoload_call)其他spl_autolo ...
- Mysql分区简述
1. 数据量大的时候 mysql分表非常常用,但是mysql还可以分区. 2. 分区就是把同一张表放在不同的磁盘文件上, 当查询的时候首先定位是哪个分区(查询的时候一定要用到分区的key) 3. 分区 ...