zoukankan      html  css  js  c++  java
  • 欧拉计划009

    一个毕达哥拉斯三元组是一个包含三个自然数的集合,a<b<c,满足条件:

    a2 + b2 = c2

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

    已知存在并且只存在一个毕达哥拉斯三元组满足条件a + b + c = 1000。

    找出该三元组中abc的乘积。

    ——————————————————————————————————————————


    用的解决方法再暴力不过了,一路循环、判断。。。

    代码如下:

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <time.h>
     4 
     5 
     6 int main (void)
     7 {
     8     int a,b,c;
     9     
    10     for(c=3;c<=997;c++)
    11     {
    12         for(b=2;b<=996;b++)
    13         {
    14             if(c>b)
    15             {
    16                 for(a=1;a<=995;a++)
    17                 {
    18                     if(a<b&&a<c&&b<c)
    19                     {
    20                         if((a*a+b*b==c*c)&&(a+b+c==1000))
    21                         {
    22                             printf("%d*%d*%d=%d\n",a,b,c,a*b*c);
    23                             break;
    24                         }
    25                     }
    26                 }
    27             }
    28         }
    29     }
    30 
    31     return 0;
    32 }

    输出结果:200*375*425=31875000;

  • 相关阅读:
    node.js
    js中文乱码问题
    238. Product of Array Except Self
    接下来要记得东西
    javascript 块内函数
    171. Excel Sheet Column Number
    Moore’s Voting Algorithm
    [ Python ] PIL
    [ Python ] KMP Algorithms
    房之事
  • 原文地址:https://www.cnblogs.com/hhccdf/p/2989131.html
Copyright © 2011-2022 走看看