1009 -- 公约数和公倍数

来源:互联网 发布:懒角落 淘宝 编辑:程序博客网 时间:2024/04/30 12:55

公约数和公倍数

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

36 612 1133 22

Sample Output

6 61 13211 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));                }            }        }    }


0 0
原创粉丝点击