乐趣区

projecteulerproblem9

problem9

地址:https://projecteuler.net/problem=9。
源码:git@code.aliyun.com:c-program/projecteuler.git。
问题:和为 1000,且满足勾股定理的数最大积。

#include <stdio.h>
#include <math.h>
#include "elr_debug.h"

#define NUM 1000

int main(int argc, char **argv){
    int a, b, c;
    long int result = 0;
    long int lResult;

    elrDebugTime(EDT_BEGIN);

    for (a=1; a < NUM / 2; a++){for (b=a+1; b < NUM; b++){
            c = NUM - a - b;
            if ((c>b) && (c*c==b*b+a*a)) {
                lResult = a * b *c;
                result = result>lResult?result:lResult;
            }
        }
    }
    
    printf("Problem9  Answer: %ld\n", result);

    elrDebugTime(EDT_SPEND);
    elrDebugTime(EDT_END);
    return 0;
}
退出移动版