C++快速求解最大公因数 | gcd库函数
2024-09-08 19:24:34
1.介绍
gcd全称 :greatest common divisor
使用 __gcd( int x1, int x2 ) 函数可以高效、迅速得到x1, x2两个数的最大公因数。省去手写底层代码,专注代码逻辑的研究
2.注意
__gcd( int x1, int x2 ) 前面是两个下划线
3.头文件及命名空间
#include<algorithm>
using namespace std;
4.示例
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<__gcd(a,b);
return 0;
}
//输入:
//288 540
//输出:
//36
5.优化
#include<iostream>
#include<algorithm>
using namespace std;
inline int gcd(int a,int b) {
return __gcd(a,b);
}
int main(){
int a,b;
cin>>a>>b;
cout<<__gcd(a,b);
return 0;
}
//输入:
//288 540
//输出:
//36
//inline()修饰功能简单的函数能提高时间效率
最新文章
- 安全防范:nginx下git引发的隐私泄露问题
- js zTree的用法
- iosTest
- android 欢迎界面的淡入效果
- HBuilder使用感受
- Python代码分析工具之dis模块
- [string]Roman to Integer,Integer to Roman
- ubuntu 设置网卡为混杂模式 以及网络配置命令
- Eclipse使用技巧总结(二)
- centos 把网卡名称修改为 eth0
- 【Conclusion】MySQL使用
- Regularity criteria for NSE 5: $u_3,\om_3$
- HTTP lab01 做一个简单的测试用 web页面
- 基于IP的docker private registry 私有仓库的搭建
- Vue.directive自定义指令
- ERROR: APK path is not specified for
- mybatis 中文做参数报错
- fis3-postpackager-loader
- 关闭Delphi的RTTI
- C#学习笔记(27)——委托排序(1)