gcd and lcm
来源:互联网 发布:阿里云ecs 发送邮件 编辑:程序博客网 时间:2024/06/14 23:16
原文链接:http://blog.csdn.net/troubleshooter/article/details/25394959点击打开链接
//**************************************************************************************************** // // 求两个自然数的最小公倍数 - C++ - by Chimomo // // 最小公倍数 = 两数的乘积 / 最大公约数 // //**************************************************************************************************** #include <iostream> #include <cassert> #include <stack> #include <math.h> using namespace std ; int GreatestCommonDivisor(int a, int b) { int temp; if(a < b) { // 交换两个数,使大数放在a的位置上。 temp = a; a = b; b = temp; } while(b != 0) { // 利用辗转相除法,直到b为0为止。 temp = a % b; a = b; b = temp; } return a; } int LeastCommonMultiple(int a, int b) { int temp = a * b / GreatestCommonDivisor(a, b); return temp; } int main() { cout << LeastCommonMultiple(318, 87632) << endl; return 0; } // Output: /* 13933488 */
阅读全文
0 0
- hdu4497 GCD and LCM
- GCD and LCM
- hdu4497 GCD and LCM
- hdu5341 Gcd and Lcm
- hdu4497 lcm and gcd
- HDU4497 GCD and LCM
- GCD and LCM Aizu
- The GCD and LCM
- gcd and lcm
- GCD and LCM HDU
- GCD and LCM
- GCD and LCM HDU
- GCD and LCM HDU
- TOJ 10009 GCD and LCM
- hdu 4497 GCD and LCM
- hdu 4497 GCD and LCM
- HDU - 4497 GCD and LCM
- HDOJ 4497 GCD and LCM
- IOS学习笔记(十二)之IOS开发之表视图(UITableView)的相关类,属性与表视图实现学习(二)
- centos安装 twisted
- oracle 命令分析
- Android安卓 Listview删除/移除Item 较新方法(sdk 21)
- day01 C++名字空间、结构体、联合体、枚举 、字符串
- gcd and lcm
- 0617
- 黑匣子_KEY
- CentOS6.5下Redis安装与配置
- 事件冒泡、事件捕捉、事件委托
- mysql的小知识点
- Android的外部存储
- 9.Nginx 日志管理
- 合并排序数组II