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
- 1009 -- 公约数和公倍数
- 公约数和公倍数。。。
- NYOJ - 公约数和公倍数
- 公约数和公倍数
- 公约数和公倍数
- NYOJ40-公约数和公倍数
- 公约数和公倍数
- 公倍数和公约数
- NYOJ40公约数和公倍数
- 公约数和公倍数
- nyoj40公约数和公倍数
- 公约数和公倍数
- 40 公约数和公倍数
- NYOJ40 公约数和公倍数
- 公约数和公倍数
- nyoj40公约数和公倍数
- 公约数和公倍数
- 公倍数和公约数
- 1005 -- 构造表达式
- 1006 -- 5个数求最值
- 3、iOS 开发之 UIScrollView UIPageController NSTimer
- 1007 -- Fibonacci 数
- 1008 -- 大小写互换
- 1009 -- 公约数和公倍数
- Binary Tree Paths
- 1010 -- 青蛙的约会
- 1032. Sharing (25)
- 4、iOS 开发之 UITableView
- Add Digits
- 5、通知和代理区别和使用
- 6、iOS 开发之 UIPickerView
- 1067. Sort with Swap(0,*) (25)