【杭电】[1108]最小公倍数
2015-12-20 11:25
323 查看
基础的一种求最小公倍数
用乘积除以最大公约数
求最大公约数的方法……
话说学长说没听说过这种……
-.-
[code]#include<stdio.h> int main() { int a,b,m; while(scanf("%d %d",&a,&b)!=EOF) { m=a*b; while(a!=b) { if(a>b) a-=b; if(b>a) b-=a; } printf("%d\n",m/a); } return 0; }
然后交给我一种更快速的递归函数
求最大公约数的
[code] int gcd(int a,int b) { if(b==0) { return a; } return gcd(b,a%b); }
所以求最小公倍数的可以写成
[code]int lcm(int a,int b) { return a/gcd(a,b)*b; }
[1108]最小公倍数
相关文章推荐
- MVC6的内置ActionResult类型
- 【music player】项目问题随笔记录
- ListView的OnScrollListener接口
- php封装好的人民币数值转中文大写类
- Python + Mongodb数据存储
- abap alv multiple header using write
- (二)我的Makefile学习冲动&&编译过程概述
- Maven 3.3 JDK1.7
- Mysql优化
- hive executeTask被interrupt处理
- rp++ find ROP sequences
- 二叉树创建、三种遍历、叶子节点数
- js函数库大全
- 再次回来
- Intellij Idea快捷键
- 基于高度差的地形LOD与平截头体剪裁
- 自定义通知 NSNotification
- 新浪云存储SCS的使用
- 第24讲:Scala中SAM转换实战详解
- 【Win 10应用开发】把文件嵌入到XML文档