fork download
  1. //! (c) WhiZTiM __ionogu(<_at_)>acm.org
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. struct Triples {
  8. Triples() = default;
  9. Triples(unsigned aa, unsigned bb, unsigned cc): a(aa), b(bb), c(cc) {}
  10. unsigned a=0; unsigned b=0; unsigned c=0;
  11. };
  12. using vTriples = vector<Triples>;
  13.  
  14. Triples triples(size_t lower, size_t max, size_t num){
  15. Triples ans;
  16. for(size_t x=lower; x<max; x++)
  17. for(size_t y=x; y<max; y++)
  18. for(size_t z=y; z<max; z++)
  19. if((x*x + y*y == z*z) and x + y + z == num)
  20. return Triples(x, y, z);
  21. return ans;
  22. }
  23.  
  24. int main() {
  25. auto t = triples(1, 1000, 1000);
  26. cout << t.a << ", " << t.b << ", " << t.c << '\n';
  27. cout << "Product: " << t.a * t.b * t.c << '\n';
  28. return 0;
  29. }
Success #stdin #stdout 0.14s 3140KB
stdin
Standard input is empty
stdout
200, 375, 425
Product: 31875000