阅读背景:

基础语言-题目40(求最大公约数和最小公倍数)

来源:互联网 

主要用到的还是gcd函数,很简单的一道题目,大家看看代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int gcd (int a, int b)
{
	return a % b == 0 ? b : gcd (b, a % b);  
}
// 主要是一个gcd函数的运用,主要是回回写gcd的时候,都不知道如果a不能整除b的时候的应该递归调用的
// 参数是什么,现在清楚了,应该举一个很简单的例子的.比如,15和6,一下子就清楚了.呼呼.
 
int main ()
{
	int N;
	cin >> N;
	while (N--)
	{
		int a, b;
		cin >> a >> b;
		int Gcd = gcd (a, b);
		int temp = a * b / Gcd;
		cout << Gcd << " " << temp << endl;
	}
	return 0;
}

	
#include <st



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: