Didn't understand time complexity of code

int gcd(int n, int m)
{
if (n%m ==0) return m;
if (n < m) swap(n, m);
while (m > 0)
{
n = n%m;
swap(n, m);
}
return n;
}

it should be log(n)

on each iteration, the value of n reduces by a factor of the golden ratio on average. I suggest trying to work out the worst case and it should be about log base 1.618 of n

For more details https://en.wikipedia.org/wiki/Euclidean_algorithm which notes “If the Euclidean algorithm requires N steps for a pair of natural numbers a > b > 0, the smallest values of a and b for which this is true are the Fibonacci numbers F(N+2) and F(N+1), respectively.”

e.g. If you start with Fib(n+2) and Fib(n+1) you will get Fib(n) and Fib(n+1) on the next iteration until you stop at 1.