Блог пользователя Saiyan_1991

Автор Saiyan_1991, история, 6 лет назад, По-английски

my g++ version is 9.3.0 but std::lcm() std::gcd() is not working. An error message is showing that "'lcm' was not declared in this scope" or "'gcd' was not declared in this scope". what should I do?

UPD: problem solved...keeping this post for those people who are encountering similar problem.

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

There're no such functions called gcd() or lcm(). (only before C++17,thanks MohamedMagdy for correcting my mistake)

However, there're something called __gcd()

If you want the GCD of a and b, you can write the following code:

int gcd(int a,int b){
    if(b==0)return a;
    else return gcd(b,a%b);
}

And for LCM:

int lcm(int a,int b){
    return a*b/gcd(a,b);
}
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Try to compile with -std=c++17 option.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I compile with -std=c++2a and both gcd and lcm work. You can get C++20 (beta?) compiler from here : http://mingw.org/