【Project Euler】【Problem 9】Special Pythagorean triplet

本文探讨了一个特定的数学问题——寻找满足特定条件的毕达哥拉斯三元组,即三个自然数a、b、c满足a^2 + b^2 = c^2且a + b + c = 1000,并提供了一种编程解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Special Pythagorean triplet

Problem 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.


Answer:
31875000

翻译:

特别的毕达哥拉斯三元数组

问题 9

一个毕达哥拉斯三元数组是有三个自然数组成a < b < c, 满足 a2 + b2 = c2

例如, 32 + 42 = 9 + 16 = 25 = 52.

存在一个正确的毕达哥拉斯三元数组满足 a + b + c = 1000.
找到abc的乘积.


答案:
31875000
解法一:
#include <stdio.h>

int main(int argc, char *argv[])
{
    int a=1;
    int b=1;
    int c=1;

    int range = 1000;
    for (a=1; a < range; a++)
    {
        for (b=1; b < range - a; b++)
        {
			c = range-a-b;
			if (a*a+b*b==c*c)
			{
				printf("result is %d \n",a*b*c);
				return 0;
			}
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值