C++ reported error'__gcd' was not declared in this scope

error

Recently want to use __gcd(a, b)computing aand bthe greatest common divisor, the results encountered the following error:

[Error] '__gcd' was not declared in this scope

Solution

Because the __gcd()function is defined in the standard library <algorithm>, just add it #include <algorithm>.
Example:

#include <cstdio>
#include <algorithm>
using namespace std;

int main(void)
{
    
    
	int a, b;
	scanf("%d%d"&a, &b);
	printf("%d\n", __gcd(a, b));
	return 0;
}

Guess you like

Origin blog.csdn.net/write_1m_lines/article/details/104753636