project-euler

https://projecteuler.net/
Log | Files | Refs | README

Euler_86.cpp (1023B)


      1 #include "Euler.h"
      2 
      3 //this can be sped up significantly by not recalculating previously found solutions but cba tbh fam
      4 //precalculating all the squares might also be worth it, but would be a minor optimisation compared to above
      5 uint64_t Euler::CuboidRoute()
      6 {
      7     for (int M = 100;; ++M) { 
      8         uint64_t solutions = 0;
      9 
     10         for (int sp = 1; sp < sqrt(pow(M + M, 2) + pow(M, 2)); ++sp) {
     11             for (int i = 1; i < sp; ++i) {
     12                 double c = sqrt((sp * sp) - (i * i));
     13 
     14                 if (c == (int)c && (int)c <= M) {
     15                    for (int j = 1; j <= i / 2; ++ j) {
     16                        if (j <= M && (i - j) <= M && (i - j) <= c) {
     17                             //std::cout << "(" << j << " + " << i - j << ")² + " << (int)c << "² = " << sp << "²" << std::endl;
     18                             solutions += 1;
     19                        }
     20                     }
     21                 }
     22             }
     23         }
     24 
     25         if (solutions > 1000000) {
     26             return M;
     27         }
     28     }
     29 
     30     return 0;
     31 }