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

/*
最小公倍数
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;
}

posted on 2017-05-01 15:59  yjbjingcha  阅读(222)  评论(0编辑  收藏  举报

导航