Project Euler Homework

009.cpp

Go to the documentation of this file.
00001 
00011 #include <iostream>
00012 using namespace std;
00025 int
00026 main ()
00027 {
00028   int m, n;
00029   for (m = 2; m <= 22; m++)
00030     {
00031       int temp = 500 - m * m;
00032       if (temp % m != 0)
00033         continue;               //n should be an integer
00034 
00035       n = temp / m;
00036       if (n < m)
00037         break;                  //a,b should be positive
00038     }
00039   if (n >= m)
00040     {
00041       cout << "no possible solution" << endl;
00042       return 0;
00043     }
00044 
00045   cout << "(m,n)=(" << m << ',' << n << ')' << endl;
00046 
00047   int a = 2 * m * n, b = m * m - n * n, c = m * m + n * n;
00048   cout << "(a,b,c)=(" << a << ',' << b << ',' << c << ')' << endl;
00049   cout << "product of a,b,c = " << (long (a) * b * c) <<endl;
00050   return 0;
00051 }
00052 
 All Classes Files Functions Variables