From db74198956af276cb9e740b0e87723bbfab78e38 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Mon, 15 Jun 2020 20:06:52 -0400 Subject: [PATCH] Updated for performance --- Headers/Problem9.hpp | 2 +- Source/Problem9.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Headers/Problem9.hpp b/Headers/Problem9.hpp index 045fee4..fd82bff 100644 --- a/Headers/Problem9.hpp +++ b/Headers/Problem9.hpp @@ -53,7 +53,7 @@ public: /* Results: The Pythagorean triplet is 200 375 425 The numbers' product is 31875000 -It took 146.100 microseconds to solve this problem. +It took 0.000 nanoseconds to solve this problem. */ #endif //PROBLEM9_HPP diff --git a/Source/Problem9.cpp b/Source/Problem9.cpp index da3f7b0..63f94db 100644 --- a/Source/Problem9.cpp +++ b/Source/Problem9.cpp @@ -45,12 +45,12 @@ void Problem9::solve(){ //Loop through all possible a's while((a < 1000) && !found){ b = a + 1; //b bust be greater than a - c = sqrt(pow(a, 2) + pow(b, 2)); + c = sqrt((a * a) + (b * b)); //Loop through all possible b's while((a + b + c) < 1000){ ++b; - c = sqrt(pow(a, 2) + pow(b, 2)); + c = sqrt((a * a) + (b * b)); } //If the sum == 1000 you found the number, otherwise go to the next possible a