游客 Signup | Login
中文 | En

2115 - 求三个数的最小公倍数

1.     编写程序,求任意三个数的最小公倍数。

要求用子函数和Driver的形式编写代码。你需要设计求3个数最小公倍数的子函数。例如:

input:

20 50 30
output:
300

Input

三个整数

Output

三个整数的最小公倍数

Examples

Input

2 5 3

Output

30

Solution C

#include <stdio.h>

int f(int a,int b)
{
    if ( !(a%b) )   return b;
    return f(b,a%b);
}

int main(void)
{
    int a,b,c;
    int res;

    scanf("%d %d %d",&a,&b,&c);
    res = a * b / f(a,b);
    res = res * c / f(res,c);
    printf("%d\n",res);
    return 0;
}

Solution C++

#include <iostream>
using namespace std;
int main()
{
	long a;
	long b;
	long c;
	long max;
	int i=2;
	cin >>a >>b>>c;
	if(a>b&&a>c)
		max=a;
	if(b>a&&b>c)
		max=b;
	if(c>a&&c>b)
		max=c;
	while(max%a!=0||max%b!=0||max%c!=0)
	{
		max=max++;
		
	}
	cout <<max<<endl;
	return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题