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
Sample Output
Source
经典题目
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)); } } } }
相关文章推荐
- 1008 -- 大小写互换
- lvm基本应用,扩展及缩减实现
- 1007 -- Fibonacci 数
- 3、iOS 开发之 UIScrollView UIPageController NSTimer
- 1006 -- 5个数求最值
- 1005 -- 构造表达式
- LeetCode Palindrome Linked List
- LeetCode Palindrome Linked List
- 1004 -- “顺”序列
- Longest Substring Without Repeating Characters
- 2、iOS 开发之字典转模型和 xib
- 1003 -- 计算N!
- Hello World Using Struts 2
- 1002 -- 手机靓号
- 1095. Cars on Campus (30)
- 1001 -- ACM"水题"
- mysql导入sql文件时乱码问题
- 1000 -- A+B Problem
- 视觉交互的知识总结
- 【如何通过广域网访问局域网的服务器?】