我正在编写一个混合数字类,需要一个快速简单的“最大公约数”函数。谁能给我代码或代码链接?
最佳答案
libstdc++ 算法库有一个隐藏的 gcd 函数(我使用的是 g++ 4.6.3)。
#include <iostream>
#include <algorithm>
int main()
{
cout << std::__gcd(100,24);
return 0;
}
不客气:)
更新:正如@chema989 所指出的,在 C++17 中有 std::gcd()
<numeric>
提供的功能标题。
关于c++ - C++ sans cmath库中的GCD函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10956543/