A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a2 + b2 = c2

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的更多相关文章

  1. 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) ...

  2. (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 ...

  3. Special Pythagorean triplet

    这个比较简单,慢慢进入状态. A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = ...

  4. projecteuler----&gt;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 ...

  5. Project Euler Problem 9-Special Pythagorean triplet

    我是俩循环暴力 看了看给的文档,英语并不好,有点懵,所以找了个中文的博客看了看:勾股数组学习小记.里面有两个学习链接和例题. import math def calc(): for i in rang ...

  6. 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 = ...

  7. Python练习题 037:Project Euler 009:毕达哥拉斯三元组之乘积

    本题来自 Project Euler 第9题:https://projecteuler.net/problem=9 # Project Euler: Problem 9: Special Pythag ...

  8. Project Euler Problem9

    Special Pythagorean triplet Problem 9 A Pythagorean triplet is a set of three natural numbers, a  b  ...

  9. PE 001~010

    题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的 ...

随机推荐

  1. Android Framework层Power键关机流程(二,关机流程)

    二,关机流程 从前一篇博文我们知道,当用户长按Power键时会弹出(关机.重启,飞行模式等选项)对话框,我们点击关机,则会弹出关机确认对话框.那么从选项对话框到关机确认对话框又是一个什么流程呢.下面我 ...

  2. Simple Maven Project

    为pom.xml添加组织,法律和开发人员信息 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...

  3. M5: 使用StorageFile

    本小节介绍UWP中的文件操作,使用到了FileOpenPickerAPI(在Windows.Storage.Pickers中).本例中,单击打开文件按钮,然后在图片库中选择照片,将选择的照片用作贺卡背 ...

  4. Linux 进程退出后自动启动

    /********************************************************************** * Linux 进程退出后自动启动 * 说明: * 在系 ...

  5. python数据结构与算法——栈

    # 栈# 其实python里面的list就可以当栈使用啦,用collections.deque也可以# 1. 入栈 list.append(item)# 2. 出栈 item = list.pop() ...

  6. Jena TDB assembler syntax

    1 introduction Assembler is a DSL of Jena to specify something to build, models and dataset, for exa ...

  7. [转]STL中vector转数组(实际是数组的指针)

    感谢:http://topic.csdn.net/t/20050429/20/3976956.html 感谢:http://yzyanchao.blogbus.com/logs/47796444.ht ...

  8. JS判断是否来自手机移动端的访问,并跳转

    var browserName_ = navigator.userAgent ; &&browserName_.indexOf(&&browserName_.index ...

  9. java端口扫描(原创)

    项目需要扫描占用的端口来判断服务是否启动,通过查资料发现大多数方法都是ServerSocket socket = new ServerSocket(port);代码如下: package com.fr ...

  10. sublimetext 使用正则表达式匹配中文

    [\x{4e00}-\x{9fa5}] ============================================= 参考资料 1.在javascript下正确的\x4e00-\x9fa ...