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的 ...
随机推荐
- 北大poj-1062
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43523 Accepted: 12760 Descripti ...
- 闭包的理解-from my own opinion
闭包,说起来那么难,其实理解了作用域,那么理解闭包就容易多了. 全局环境,局部环境,这两个概念很好理解了.那么要深入理解下函数的局部环境. 函数的局部环境,也就是说在一个函数内定义的变量,这个变量只能 ...
- php-eclipse乱码处理
方法一:1)设置"eclipse目录下eclipse.ini文件"2)在文件结尾添加"-Dfile.encoding=UTF-8".3)重新启动eclipse, ...
- HDU 2577(DP)
题意:要求一个字符串输入,按键盘的最少次数.有Caps Lock和Shift两种转换大小写输入的方式 思路:用dpa与dpb数组分别记录Caps Lock的开关状态,dpa表示不开,dpb表示开 代码 ...
- mysql特殊处理
mysql> create table ef (bc time);Query OK, 0 rows affected (0.03 sec) mysql> insert into ef va ...
- dbms_stats包更新、导出、导入、锁定统计信息
dbms_stats包问世以后,我们可通过一种新的方式来为CBO收集统计数据.目前,已经不再推荐使用老式的Analyze分析表和dbms_utility方法来生成CBO统计数据.dbms_stats能 ...
- linux系统的初化始配置 IP 主机名 防火墙 selinux
本次内容包括Linux:ip.主机名.关闭firewalld与selinux 开机临时生效和永久生效 ------------------------------------------------- ...
- [2014.01.27]WFsoft.wfWebCtrl.wfUrlPager 3.2
wfUrlPager多功能.Net翻页组件,使用简单,功能强大. 提供"首页","上一页","下一页","末页",&qu ...
- 基于Open vSwitch搭建虚拟路由器
As part of my work in OpenDaylight, we are looking at creating a router using Open vSwitch... Why? W ...
- SSIS 参数与环境
微软 BI 系列随笔 - SSIS 基础 - 参数与环境 简介 在上一篇博客中,主要讲述了如何实现SSIS的项目部署,参见 微软 BI 系列随笔 - SSIS 2012 基础 - SSIS 项目部署模 ...