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. React Native组件之ScrollView 和 StatusBar和TabBarIos

    React Native中的组件ScrollView类似于iOS中的UIScrollView,其基本的使用方法和熟悉如下: /** * Sample React Native App * https: ...

  2. Windows Squid 安装配置

    squid 可以做反向代理将系统中相对静态的页面进行缓存和负责均衡,提高网站访问速度,增强网站可用性.安全性.用户访问Squid 反向代理服务器的 IP 地址,这样客户端的 URL 请求将被发送到反向 ...

  3. Windows上管理远程Linux VPS/服务器文件工具 - winscp

    Linux上经常会经常需要编辑文件,特别是Linux VPS/服务器安装好系统之后配置环境会需要修改很多的配置文件等,对于常用Linux的基本上都能够熟练使用vi或者nano等SSH下面的文件编辑工具 ...

  4. php用压栈的方式,循环遍历无限级别的数组(非递归方法)

    php用压栈的方式,循环遍历无限级别的数组(非递归方法) 好久不写非递归遍历无限级分类...瞎猫碰到死老鼠,发刚才写的1段代码,压栈的方式遍历php无限分类的数组... php压栈的方式遍历无限级别数 ...

  5. C++学习笔记21:文件系统

    文件系统 实际文件系统 ext, ext2, ext3, ext4 虚拟文件系统 VFS 特殊文件系统/proc:从proc文件系统中抽取信息 实际文件系统:组成与功能描述 引导块,超级块,索引结点区 ...

  6. Python 基礎 - bytes數據類型

    三元運算 什麼是三元運算?請看下圖說明 透過上圖說明後,可以得出一個三元運算公式: result = 值1 if 條件 else 值2, 如果鯈件為真: result = 值1 如果鯈件為假: res ...

  7. Thrift 个人实战--Thrift 服务化 Client的改造

    前言: Thrift作为Facebook开源的RPC框架, 通过IDL中间语言, 并借助代码生成引擎生成各种主流语言的rpc框架服务端/客户端代码. 不过Thrift的实现, 简单使用离实际生产环境还 ...

  8. Jena TDB assembler syntax

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

  9. mm/swap

    /* *  linux/mm/swap.c * *  Copyright (C) 1991, 1992  Linus Torvalds */ /* * This file should contain ...

  10. appserv升级php

    安装thinkphp的时候提示必须要php5.3及以上 本地测试服务器使用的是appserv集成环境 所以要单独升级php 首先到官网下载http://php.net/downloads.php wi ...