首页 > 其他 > 详细

最小公倍数 【杭电-HDOJ-1108】 附题+具体解释

时间:2017-05-01 16:37:00      阅读:323      评论:0      收藏:0      [点我收藏+]

/*
最小公倍数
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32933    Accepted Submission(s): 18398

Problem Description
给定两个正整数,计算这两个数的最小公倍数。
 

Input
输入包括多组測试数据,每组仅仅有一行,包括两个不大于1000的正整数.
 
Output
对于每一个測试用例,给出这两个数的最小公倍数,每一个实例输出一行。

Sample Input
10 14
 

Sample Output
70

*/
#include<stdio.h>         //递归思想
int swap(int a,int b)
{
 if(a>b)
 {
  return !b?

a:swap(b,a%b);
 }
 else if(a<b)
 {
  return !a?b:swap(a,b%a);
 }
 else return a;
}
int main()
{
 int a,b;
 while(~scanf("%d %d",&a,&b))
 {
  printf("%d\n",a*b/swap(a,b));
 }
 return 0;
}

最小公倍数 【杭电-HDOJ-1108】 附题+具体解释

原文:http://www.cnblogs.com/yjbjingcha/p/6792071.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!