欧拉计划第9题题解

Special Pythagorean triplet

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

\(a^2 + b^2 = c^2\)

For example, \(3^2 + 4^2 = 9 + 16 = 25 = 5^2\) .

There exists exactly one Pythagorean triplet for which \(a + b + c = 1000\) .Find the product \(abc\).

特殊毕达哥拉斯三元组

毕达哥拉斯三元组是三个自然数 \(a < b < c\) 组成的集合,并满足

\(a^2 + b^2 = c^2\)
例如,\(3^2 + 4^2 = 9 + 16 = 25 = 5^2\)。

有且只有一个毕达哥拉斯三元组满足 \(a + b + c = 1000\)。求这个三元组的乘积 \(abc\)。

解题思路

没有想到比较好的办法,尝试枚举找出答案。

实现代码如下:

#include <bits/stdc++.h>
using namespace std;
int main() {
    for (int i = 1; i <= 1000/3; i ++) {
        for (int j = i; j < 1000-i-j; j ++) {
            int k = 1000 - i - j;
            if (i*i + j*j == k*k) {
                // cout << i << ", " << j << ", " << k << endl;
                cout << i * j * k << endl;
            }
        }
    }
    return 0;
}

运行后发现这对三元组为 \(200, 375, 425\),答案为 \(31875000\)。

原文地址:https://www.cnblogs.com/quanjun/p/12322970.html

时间: 2024-08-29 14:47:15

欧拉计划第9题题解的相关文章

欧拉计划第3题题解

Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 最大质因数 13195的所有质因数为5.7.13和29. 600851475143最大的质因数是多少? 解题思路 分解质因数的算法是 \(O( \sqrt{n} )\) 的算法. 求一个数 \(a\) 的质因数,可以从 \(2\) 开始到

欧拉计划第10题题解

Summation of primes The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 素数的和 所有小于10的素数的和是2 + 3 + 5 + 7 = 17. 求所有小于两百万的素数的和. 解题思路 没有特别好的想法,下奶能想到的就是枚举算出200万以内的所有素数,然后求这些素数的和. 实现代码如下: #include <bits/st

欧拉计划第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 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 8586156078911

欧拉计划第13题题解

Large sum Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629

欧拉计划&#183;第十一题

题目11:在20×20的网格中同一直线上四个数的最大乘积是多少? 在以下这个20*20的网格中,四个处于同一对角线上的相邻数字用红色标了出来: 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 6

欧拉计划&#183;第十题

题目10:计算两百万以下所有质数的和. 10以下的质数的和是2 + 3 + 5 + 7 = 17. 找出两百万以下所有质数的和. 源码 STDMETHODIMP COuLa::Test10(int number) { // TODO: 在此添加实现代码 __int64 sum = 2; for(int i = 2; 2*i-1 <= number; i++) { int c = 2*i-1; for( int j = 2;c>10? j<=10 : j<=c;j++) { if(1

欧拉计划&#183;第七题

题目7:找出第10001个质数. 前六个质数是2,3,5,7,11和13,其中第6个是13. 第10001个质数是多少? 源码 STDMETHODIMP COuLa::Test7(int number) { // TODO: 在此添加实现代码 int iNumberForCout = 1; int iNumberForOutput = 0; int iNumberForAdd = 1; while(iNumberForCout<number) { iNumberForAdd++; iNumber

欧拉计划&#183;第八题

题目8:找出这个1000位数字中连续13个数字乘积的最大值. 找出以下这个1000位的整数中连续13个数字的最大乘积. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 1254069874715852386305071569329096329

欧拉计划&#183;第五题

题目5:找出最小的能被1-20中每个数整除的数. 2520是最小的能被1-10中每个数字整除的正整数. 最小的能被1-20中每个数整除的正整数是多少? 源码 STDMETHODIMP COuLa::Test5(int number) { // TODO: 在此添加实现代码 int iForNumber[MAX_PATH] = {0}; int iForFinalNumber[MAX_PATH] = {0}; for(int i = number; i>0; i--) { int c = i; i