您的位置:首页 > 其它

1009 -- 公约数和公倍数

2015-08-29 03:27 459 查看
公约数和公倍数
Time Limit:1000MS Memory Limit:65536K

Total Submit:500 Accepted:321
Description
小明被一个问题给难住了,现在需要你帮帮忙。问题是:给出两个正整数,求出它们的最大公约数和最小公倍数。

Input
第一行输入一个大于0的整数n(n<=20),示有n组测试数据随后的n行输入两个整数i,j(i,j小于32767)。

Output
输出每组测试数据的最大公约数和最小公倍数

Sample Input
3
6 6
12 11
33 22

Sample Output
6 6
1 132
11 66

Source
经典题目

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1009 {
class Program {
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
while (n-- > 0) {
string[] sb = Console.ReadLine().Split();
int a = int.Parse(sb[0]), b = int.Parse(sb[1]);
Console.WriteLine("{0} {1}", gcd(a, b), lcm(a, b));
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: