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的 ...
随机推荐
- 【RobotFramework自动化测试】RFS常用脚本
读取后台数据文件:Import Variables | ${CURDIR}/\ABC.py 定位页面:Wait Until Keyword Succeeds | 5s | 500ms | select ...
- js常见函数汇总
/** * 隐藏元素 * @param {String} elem */ function hide(elem){ var curDisplay = getStyle(elem, 'di ...
- UVA 572
这是一道纯正的深度优先搜索题目. 题目要求在有多少个不同的块,而不同块的定义则是,一个块中的任意一点和l另一个块中的任意一点不会相连,而相连的定义则是 在横向.纵向和对角线上相连. #include& ...
- codeforces195a
link:http://codeforces.com/problemset/problem/336/A 很简单的一道题目,当初有个单词不认识,isosceles原来意思是等腰的o(╯□╰)o #inc ...
- C语言实现的Web服务器(转-kungstriving)
自己研究了好几天终于写出来一个,哈哈,当然也从网上得到了很多的帮助拉.谢谢大家咯!这个版本还不是很完善,但Web服务器的基本框架已经出来了,还有部分的功能需要进行进一步的测试和修改.虽然说C的开发比较 ...
- Android——课堂整理:assets目录和手机外部存储
layout文件: <Button android:layout_width="match_parent" android:layout_height="wrap_ ...
- 修改Apache的最大连接数
Apache的最大连接数,默认为256个. 修改apache的最大连接数,方法如下: 一:先修改./apache/conf/httpd.conf文件. # vi httpd.conf 将“#Inclu ...
- 排序算法总结(三)选择排序【Select Sort】
一.原理 选择排序的原理非常简单,就是选出最小(大)的数放在第一位,在剩下的数中,选出最小(大)的数,放在第二位......重复上述步骤,直到最后一个数. 二.过程 原始数据 第一次排序,选出最小的数 ...
- C#中获取服务器IP,客户端IP以及网卡物理地址
客户端ip: Request.ServerVariables.Get("Remote_Addr").ToString(); 客户端主机名: Request.ServerVariab ...
- js计算日期之间的月份差
<script type="text/javascript"> getMonthBetween("2015-05-01","2016-05 ...