martes, 13 de marzo de 2012

Project Euler 39

#include <iostream>
using namespace std;
int main()
{
    int v[1001], a, b, c;
    for( a = 1000 ; a >= 0 ; a--) v[a] = 0 ;
    for ( c = 1; c <= 1000; c++)
        for ( b = 1; b < c; b++)
            for ( a = 0; a <= b; a++)
                if(a+b>c && b-a<c && a+b+c <= 1000 && c*c == a*a+b*b)
                    v[a+b+c]++;
    b = 0 ;
    for ( a = 0; a <= 1000; a++)
        if(v[a]>v[b])
            b = a;
    cout << b << endl;
    return 0;
}

No hay comentarios:

Publicar un comentario