GCD and LCM


Descriptions:

Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.

Input

Input consists of several data sets. Each data set contains a and b separated by a single space in a line. The input terminates with EOF.

Constraints

  • 0 < a, b ≤ 2,000,000,000
  • LCM(a, b) ≤ 2,000,000,000
  • The number of data sets ≤ 50

Output

For each data set, print GCD and LCM separated by a single space in a line.

Sample Input

8 6

50000000 30000000

Output for the Sample Input

2 24

10000000 150000000

题目链接:

https://vjudge.net/problem/Aizu-0005

多组输入,就是求这两个数的gcd(最大公约数)和lcm(最小公倍数)

注意数据有点大,保险起见用long long吧

AC代码

 #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
if(b==)
return a;
return gcd(b,a%b); //递归求最大公约数
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b; //递归求最小公倍数
}
int main()
{
ll a,b;
while(cin >> a >> b)
{
cout << gcd(a,b)<< " "<<lcm(a,b)<<endl;
}
return ;
}

最新文章

  1. 原生js+本地储存登录注册
  2. Android监听应用程序安装和卸载
  3. HTML常用命名和CSS reset代码【收集总结】
  4. Discuz! 的编码规范
  5. 使用SQLite数据库和Access数据库的一些经验总结
  6. mysql忘记root密码
  7. java中compareTo和compare方法之比较
  8. iOS后台如何保持socket长连接和数据传输
  9. CF下Split的使用
  10. android 删除文件以及递归删除文件夹
  11. 如何导出远程oracle数据库中的表结构
  12. Jenkins在windows上的安装配置
  13. Python----Windows环境下安装Flask
  14. nginx把POST转GET请求解决405问题
  15. springboot情操陶冶-web配置(三)
  16. 虚拟机安装+配置federa
  17. flume知识点总结
  18. Linux设备驱动之Ioctl控制【转】
  19. 192 Word Frequency
  20. _event_team

热门文章

  1. ios UITableView 获取点击cell对象
  2. payload和formData有什么不同?
  3. crm使用soap删除下拉框
  4. SDUT 3503 有两个正整数,求N!的K进制的位数
  5. Spring学习笔记——Spring中lazy-init与abstract具体解释
  6. HDU 1824 Let&amp;#39;s go home (2-SAT判定)
  7. 网络知识: 物理层PHY 和 网络层MAC
  8. Random产生随机数问题
  9. POJ3761 Bubble Sort
  10. 【iOS系列】-UITableViewCell的展开与收缩的实现思路