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. OpenSSL - 文件和字符MD5加密实现

    OpenSSL安装: 1.github下载最新的OpenSSL:https://github.com/openssl/openssl 2.在linux解压压缩包 3.安装OpenSSL ./confi ...

  2. UWP/Win10新特性系列—App Service

    Win10中,新增了一个很实用的新特性叫做App Service,App Service允许App不在前台运行的情况下提供出一个或多个对外服务供其他App使用,这看起来就好像Web开发中的Web Ap ...

  3. linux 远程管理

    启动linuxssh 服务: /etc/init.d/ssh 启动网络服务: service network restart linux远程登录配置过程: 首先在ubuntu下安装openssh-se ...

  4. 引用计数gc机制使用不当导致内存泄漏

    上一篇文章找同事review了一下,收到的反馈是铺垫太长了,我尽量直入正题,哈哈 最近dbd压测时发现内存泄漏,其实这个问题去年已经暴露了,参见这篇博客[压测周].当时排查不够仔细,在此检讨下.关于d ...

  5. ucos3的配置文件

    1,配置文件,用于系统的裁剪 均有详细的注释 为组件的开关 ​ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...

  6. 类似title的鼠标跟随事件

    $(document).ready(function(){ // 创建一个div显示提示信息 var dropTitle = document.createElement("div" ...

  7. MFC ListContrl 的使用

    m_ISESTList.SetExtendedStyle(m_ISESTList.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINE ...

  8. js中的this指针(二)

    在 js 中声明并定义一个函数后,除了定义时传入的形式参数,函数还会接收到 2 个附加的参数:this 和 arguments. this 指针的值取决于调用时的模式. 当这个函数被保存为对象的一个属 ...

  9. 【maven】之使用tomcat7-maven-plugin自动编译的问题

    今天遇到一个奇怪的问题,项目依赖关系如下, 在web端通过tomcat7插件debug模式启动项目的时候,dao层写的代码不能加载,还是原来的代码效果, 然后我在eclipse部署一个tomcat,将 ...

  10. Hibernate5.2之HQL查询

    Hibernate5.2之HQL查询                                                                  一. 介绍 Hibernate的 ...