GCD and LCM

Time limit 1000 ms

Memory limit 131072 kB

Problem Description

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


解题心得:

  1. 就是给你两个数,要求输出GCD和LCM。
  2. 其实就是求个GCD,LCM = a*b/GCD

#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
typedef long long ll; ll __gcd(ll a,ll b) {
if(b == 0)
return a;
return __gcd(b,a%b);
} int main() {
ll a,b;
while(scanf("%lld%lld",&a,&b) != EOF){
ll gcd = __gcd(a, b);
ll lcm = a * b / gcd;
printf("%lld %lld\n", gcd, lcm);
}
return 0;
}

最新文章

  1. AX2012单元格显示颜色 displayOption
  2. 【leetcode】Binary Tree Preorder Traversal (middle)★
  3. BP(back propagation)反向传播
  4. codeforces 719B:Anatoly and Cockroaches
  5. 【转】unity地形插件T4M使用帮助
  6. JS 防止表单重复提交
  7. 最大流问题Ford-Fulkerson方法(转)
  8. Android用户界面 UI组件--自动提示输入框 AutoCompleteTextView和MultiAutoCompleteTextView
  9. 【(阶乘的质因数分解)算组合数】【TOJ4111】【Binomial efficient】
  10. matlab GUI之常用对话框(四)-- 输入对话框 inputdlg、目录对话框 uigetdir、列表对话框 listdlg
  11. rest_framework框架的认识
  12. PHP中如何给日期加上一个月/天
  13. python类的成员
  14. Tomcat笔记:Tomcat的执行流程解析
  15. Java 在给定路径上创建文件,所在文件夹不存在时,如何正确创建。
  16. 20170724wdVBA正则表达式提取答案到Excel
  17. AS3 - 数组元素乱序方法以及效率比较
  18. python查询mysql以字典返回
  19. Java基础(十四):泛型
  20. 【Java----字符串转义与反转义】

热门文章

  1. Python:Tkinter的GUI设计——物体实时移动
  2. 添加并发请求PDF到工作流附件
  3. 【起航计划 009】2015 起航计划 Android APIDemo的魔鬼步伐 08 App-&gt;Activity-&gt;QuickContactsDemo 联系人 ResourceCursorAdapter使用 QuickContactBadge使用
  4. Docker cgroup.procs no space left on device
  5. SQL SERVER 下:1、递归查询父分类下的各个子分类。 2、查询每个商品分类中最贵的前两个商品SQL
  6. IA32的三种地址
  7. 【BZOJ2127】happiness(网络流)
  8. 2月4号学习的一个SSM整合项目,第一课
  9. Java继承和访问修饰符
  10. How To Secure Nginx with Let&#39;s Encrypt on Ubuntu 14.04