c++ - __gcd 的时间复杂度是多少?
问题描述
__gcd(m,n) 函数的时间复杂度是多少?另外,它是否使用欧几里得方法来计算gcd?
例如代码
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
cout << "gcd(10, 25) : " << __gcd(6, 20) << endl;
}
解决方案
是的,它使用欧几里得方法来计算两个值的 gcd。它的复杂性是 (2) 算法,其中 n 是a和b的上限。
详细信息:https ://www.quora.com/What-is-the-time-complexity-of-Euclids-GCD-algorithm
推荐阅读
- mysql - 我如何将动态表单的值从反应发送到节点 js
- c - C语言:给定一个字符串,删除/删除包含n个元音的单词
- c++ - 如何修复代码块(语言 C)中的 ssrteam 致命错误?
- python - 带有“secondary_y”的 Matplotlib:如何将图例重新定位到左下角?
- shell - 如何在awk中修改来自ifconfig的输入
- ios - SwiftUI Picker在点击时不改变选择
- anaconda - 当我尝试执行 Pytorch 代码时出现 Win Error 5
- sql - 我创建了一个带有复合主键的表(分配给两列)并创建了另一个表,它只为一列引用外键?
- django - “CategoryDetailView”对象没有属性“get_object”
- json - 是否可以通过输入到 Django 的 JsonField() 来填写现成的数据?