Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the time complexity of __gcd?

Tags:

c++

std

What is the time complexity of __gcd(m,n) function? Also, does it use the Euclidean method to calculate gcd?

e.g. code

#include <iostream> 
#include <algorithm> 

using namespace std; 

int main() { 
    cout << "gcd(10, 25) : " << __gcd(6, 20) << endl; 
} 
like image 984
Amit Srivastava Avatar asked Dec 30 '25 10:12

Amit Srivastava


1 Answers

Yes, it use Euclidean method to calculate gcd of two values. It's complexity is 𝑂(𝑙𝑜𝑔2𝑛) algorithm, where n is the upper limit of a and b.

Details : https://www.quora.com/What-is-the-time-complexity-of-Euclids-GCD-algorithm

like image 90
Faruk Hossain Avatar answered Jan 01 '26 00:01

Faruk Hossain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!