What is the most efficient way to calculate the least common multiple of two integers?

后端 未结 14 1889

What is the most efficient way to calculate the least common multiple of two integers?

I just came up with this, but it definitely leaves something to be desired.

14条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 13:41

    C++ template. Compile time

    #include 
    
    const int lhs = 8, rhs = 12;
    
    template struct calc {
      calc() { }
    };
    
    template struct calc {
      calc() { std::cout << n << std::endl; }
    };
    
    template struct calc {
      calc() { }
    };
    
    template struct calc  {
      calc() { }
    };
    
    template struct lcm {
      lcm() {
        lcm();
        calc();
      }
    };
    
    template<> struct lcm<0> {
      lcm() {}
    };
    
    int main() {
      lcm();
    }
    

提交回复
热议问题