zoukankan      html  css  js  c++  java
  • Problem 9Project Euter

    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=M^2-N^2   
    //b=2MN
    //c=M^2+N^2
    //(M,N为正整数)
    int main()
    {
    int a,b,c;

    int flag=0;
    for(int M=3;M<=33;M++)
    {
    for(int N=3;N<M;N++)
    {
    a=M*M-N*N;
    b=2*M*N;
    c=M*M+N*N;
    if(a+b+c==1000) {flag=1;break;}
    }
    if(flag==1) break;
    }
    printf("%d,%d,%d",a,b,c);
    printf("%d",a*b*c);
    return 0;
    }
    Answer:

    31875000

  • 相关阅读:
    Celery
    高并发架构
    websocket
    git分支管理
    auto_ptr与shared_ptr
    UDP信号驱动IO
    TCP带外数据
    UDP广播
    获取mac地址
    char数组初始化
  • 原文地址:https://www.cnblogs.com/redlight/p/2422865.html
Copyright © 2011-2022 走看看