【Project Euler】8 第八题



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.

static void Main(string[] args)
        {
            for (int i = 1; i < 1000; i++)
            {
                for (int j = 1; j < 1000; j++)
                {
                    for (int k = 1; k < 1000; k++)
                    {
                        if (i + j + k == 1000)
                        {
                            if (j * j + k * k == i * i)
                            {
                                int x = i * j * k;
                                Console.WriteLine(x);
                            }
                        }
                    }
                }
            }
        }

时间: 2024-07-29 19:05:40

【Project Euler】8 第八题的相关文章

【Project Euler】1 第一题

 //If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. //Find the sum of all the multiples of 3 or 5 below 1000.  static void Main()         {             int sum=0;     

【Project Euler】2 第二题

 //Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: //1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... //By considering the terms in the Fibonacci sequence whose valu

【Project Euler】9 第九题

 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. static void Main(s

使用CoffeeScript来解决Project Euler中的编程问题

本 系列 文章将探讨 CoffeeScript,这是构建于 http://www.aliyun.com/zixun/aggregation/33906.html">JavaScript 基础之上的一种全新编程语言,它提供了非常干净的语法.CoffeeScript 可编译为高效的 JavaScript.除了在 Web 浏览器中运行 JavaScript 之外,您还可以将它与服务器应用程序的 Node.js 等技术一起使用.在 第 1 部分 中,学习了如何设置 CoffeeScript 编译器

用python解决project euler中的题目

寒假期间学习了python,现在基本上就能上手使用它来解决project euler里面的题目了,用python真的是没得说的,一个字"赞".在C++中需要用一大堆代码实现的算法,在python中,只需要那么短短几行.而且还有惊艳的运行速度.借用<可爱的python>里面的一句话:"人生苦短,我用python". [project euler 055] 求经过一系列规则不能得到回文数的数的个数.题目在此: If we take 47, reverse a

c语言-看不出来第八题为什么可以运行却输不出结果-_-||求大神帮忙看看,谢谢O(∩_∩)O

问题描述 看不出来第八题为什么可以运行却输不出结果-_-||求大神帮忙看看,谢谢O(∩_∩)O #include int main(){int abci=0;printf(""Enter number of days in month:"");scanf(""%d""&a);printf(""Enter day of the week:"");scanf(""

c语言-C语言,第八题,求大神

问题描述 C语言,第八题,求大神 大神请帮忙检查一下,是逻辑错了还是什么问题?为什么得不到正确的输出? 解决方案 int fun(int n,int a){ int sum=0; for(int i=0;i<n;i++){ sum=sum+(n-i)*a*pow((double)10,i); } return sum; } 解决方案二: return sum 不应该放while循环里面吧 解决方案三: 根据题的意思你那n和a好像搞反了,还有就是i=i++应该放在pow后面,return语句放在w

经典算法题每日演练——第八题 AC自动机

原文:经典算法题每日演练--第八题 AC自动机        上一篇我们说了单模式匹配算法KMP,现在我们有需求了,我要检查一篇文章中是否有某些敏感词,这其实就是多模式匹配的问题. 当然你也可以用KMP算法求出,那么它的时间复杂度为O(c*(m+n)),c:为模式串的个数.m:为模式串的长度,n:为正文的长度,那 么这个复杂度就不再是线性了,我们学算法就是希望能把要解决的问题优化到极致,这不,AC自动机就派上用场了.    其实AC自动机就是Trie树的一个活用,活用点就是灌输了kmp的思想,从

Project euler 18题解答

 By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 37 4 2 4 6 8 5 9 3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom of the triangle below