Created
February 11, 2026 00:43
-
-
Save dgodfrey206/7e85d54ca7d852cf1d34402ad6f97d0a to your computer and use it in GitHub Desktop.
There exists exactly one Pythagorean triplet for which a+b+c=100. Find the product abc.
This file contains hidden or 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
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // find two numbers who's squares, when added, equal a number whose square root, plus those two numbers equals 1000 | |
| int main() { | |
| cout << []{ | |
| int n = 1000; | |
| for (int a = 1; a <= n; a++) { | |
| for (int b = a + 1; b <= n; b++) { | |
| int c_squared = a * a + b * b; | |
| double cd = sqrt(c_squared); | |
| if (cd != (int)cd) { | |
| continue; | |
| } | |
| int c = cd; | |
| if (c > b && a + b + c == n) { | |
| return a * b * c; | |
| } | |
| } | |
| } | |
| return 0; | |
| }(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment