Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <math.h>
- #include <vector>
- #include <algorithm>
- #define LIMIT 500
- using namespace std;
- // Auxiliary Functions
- double hypot(int a, int b){
- return sqrt(a*a + b*b);
- }
- bool isInteger(double d){
- if(d == int(d)){
- return true;
- }
- return false;
- }
- // MAIN FUNCTION
- int main()
- {
- cout << "LIMIT = " << LIMIT << ", for a, b and c" << endl << endl;
- cout << "Time for 250^3 executions is about 2.1 seconds." << endl;
- cout << "Time for 500^3 executions is about 16.8 seconds." << endl;
- cout << "Time for 750^3 executions is about 52 seconds." << endl;
- cout << "Time for 1000^3 executions is about 125 seconds." << endl << endl;
- vector <int> triades = vector <int> ();
- int counter = 0;
- for(int a=1; a<LIMIT; a++){
- for(int b=1; b<LIMIT; b++){
- for(int c=1; c<LIMIT; c++){
- double hypot1 = hypot(a, b);
- double hypot2 = hypot(a, c);
- double hypot3 = hypot(b, c);
- if(isInteger(hypot1) == true && isInteger(hypot2) == true && isInteger(hypot3) == true && (hypot1 < hypot2) && (hypot2 < hypot3)){
- counter++;
- triades.push_back(a);
- triades.push_back(b);
- triades.push_back(c);
- cout << "**** Solution " << counter << " ****" << endl;
- cout << "(" << a << ", " << b << ", " << c << "), because: " << endl;
- cout << "x = sqrt(" << a << "^2 + " << b << "^2 = " << hypot1 << endl;
- cout << "y = sqrt(" << a << "^2 + " << c << "^2 = " << hypot2 << endl;
- cout << "z = sqrt(" << b << "^2 + " << c << "^2 = " << hypot3 << endl << endl;
- }
- } // END OF FOR-LOOP-3
- } // END OF FOR-LOOP-2
- } // END OF FOR-LOOP-1
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement