Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Created February 11, 2026 00:43
Show Gist options
  • Select an option

  • Save dgodfrey206/7e85d54ca7d852cf1d34402ad6f97d0a to your computer and use it in GitHub Desktop.

Select an option

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.
#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