Last active
June 27, 2017 14:09
-
-
Save NixImagery/7bb4cca1a07c286bc7162f375098960b to your computer and use it in GitHub Desktop.
Special Pythagorean TripleFrom https://www.hackerrank.com/contests/projecteuler/challenges/euler009/submissions/code/1302177592
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace std; | |
int main(){ | |
int t; | |
cin >> t; | |
for(int a0 = 0; a0 < t; a0++){ | |
int n; | |
int b, c; | |
long abc; | |
long max = -1; | |
cin >> n; | |
for (int a = 1; a < (n-5); ++a){ | |
b = (n * (n - (2 * a))) / (2 * (n - a)); | |
c = n - (a + b); | |
if (a*a + b*b == c*c){ | |
if (b > a){ | |
if (c > b){ | |
abc = a * b * c; | |
if (abc > max) max = abc; | |
} | |
} | |
} | |
} | |
cout << max << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment