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. STL 库中的陷阱----一个难以察觉的 bug

    请找出下面程序的 bug? int maxProfit2(vector<int> &prices) { int local[3] = {0}; int global[3] = {0 ...

  2. Python OpenCV —— bitwise

    关于图像的位操作,目的是为了将一个logo覆盖到另一个图片上. # -*- coding: utf-8 -*- """ Created on Wed Sep 28 20: ...

  3. GCD,用同步/异步函数,创建并发/串行队列

    队列  第一个参数:C语言字符串,标签 第二个参数: DISPATCH_QUEUE_CONCURRENT:并发队列 DISPATCH_QUEUE_SERIAL:串行队列 dispatch_queue_ ...

  4. git 添加ssh的方法 push免登陆

    在github.com上 建立了一个小项目,可是在每次push  的时候,都要输入用户名和密码,很是麻烦 原因是使用了https方式 push 在termail里边 输入  git remote -v ...

  5. 关于 Unix 用户权限及进程权限及 Saved set-user-id

    最近在看APUE,看到3.14节,fcntl的时候#include <fcntl.h>int fcntl(int fd, int cmd, .../* int arg */);出错返回-1 ...

  6. Erlang 104 OTP

    笔记系列 Erlang环境和顺序编程Erlang并发编程Erlang分布式编程YawsErlang/OTP 日期              变更说明 2014-12-21 A Outline, 1 A ...

  7. 防止特殊html字符的问题(xxs攻击)方法

    快速对字符转义,避免跨站攻击XSS   XSS已经成为非常流行的网站攻击方式,为了安全起见,尽量避免用户的输入.可是有些情况下不仅不避免,反而要求鼓励输入,比如写博客.博客园开放性很高,可以运行手写的 ...

  8. caffe的python接口

    http://blog.csdn.net/lu597203933/article/details/46742199 hadoop改成自己名字

  9. C++中的vector

    opencv中用到了很多vector  整理一下 vector容器是一个模板类,可以存放任何类型的对象(但必须是同一类对象).vector对象可以在运行时高效地添加元素,并且vector中元素是连续存 ...

  10. java之OOP

    类中属性的默认值 1.数字类型(int,short,byte,long,float,double)的初始化默认值是0 2.boolean的初始化默认值是false 3.引用类型的初始化默认值是null ...