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;
}

Aizu:0005-GCD and LCM的更多相关文章

  1. AOJ 0005 GCD and LCM

    题意:求两数最大公约数和最小公倍数. 类型:辗转相除法 算法:gcd(a,b)=gcd(b,a%b),lcm(a,b)=a*b/gcd(a,b). #include <cstdio> #i ...

  2. poj 2429 GCD &amp; LCM Inverse 【java】+【数学】

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9928   Accepted:  ...

  3. 【Aizu - 0005 】GCD and LCM

    GCD and LCM Descriptions: Write a program which computes the greatest common divisor (GCD) and the l ...

  4. hdu 4497 GCD and LCM 数学

    GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...

  5. GCD 与 LCM UVA - 11388

    题目链接: https://cn.vjudge.net/problem/23709/origin 本题其实有坑 数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的 思路是最大公因数的倍 ...

  6. 简单数论总结1——gcd与lcm

    并不重要的前言 最近学习了一些数论知识,但是自己都不懂自己到底学了些什么qwq,在这里把知识一并总结起来. 也不是很难的gcd和lcm 显而易见的结论: 为什么呢? 根据唯一分解定理: a和b都可被分 ...

  7. 数论----gcd和lcm

    gcd即最大公约数,lcm即最小公倍数. 首先给出a×b=gcd×lcm 证明:令gcd(a,b)=k,a=xk,b=yk,则a×b=x*y*k*k,而lcm=x*y*k,所以a*b=gcd*lcm. ...

  8. HDU 4497 GCD and LCM (合数分解)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  9. HDU 4497 GCD and LCM(数论+容斥原理)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

随机推荐

  1. XHML教会我的一些东西-4

    今天把“河畔林语”的项目看完了.我自己也试着做了一下,这算是自己写的第一个项目吧.虽然全部是模仿,而且经常一边看写好的一边自己写,还是自己不够成熟呀. 不知道为什么,我用我的电脑进http://www ...

  2. sharepoint2007就地升级2010系列(二)环境概述及升级前准备

    环境介绍:1台2GB的虚机 现在是windows server 2008 sp2 X64 +SQL 2005+SQL2005 sp3+sharepoint2007+sharepoint2007SP2 ...

  3. Azure 4月新公布

    Azure 4 月新发布:Linux 上的 Azure Service Fabric 公共预览版正式发布:Azure 物联网套件新增设备管理功能:计量名称变更 Linux 上的 Azure Servi ...

  4. Azure进阶攻略 | 你的程序也能察言观色?这个真的可以有!

    前段时间有个网站曾经火爆微博和朋友圈:颜龄机器人.只要随便上传一张包含人面孔的照片,这个网站就可以分析图片,并判断照片中人物的年龄.化妆.美颜 P 图.帽子墨镜之类的配饰,几乎都没法影响这个网站的检测 ...

  5. OMD开源监控软件

    参考 Best Monitoring Solution - OMD (Nagios + Check_MK) 官网 mathias-kettner.com OMD labs.consol.de Conf ...

  6. JDK、JRE、javac和JVM的关系

      .java为Java的源文件后缀,编写的代码需要写在.java文件中.     Javac编译器,用于读取Java源代码,并将其编译成字节代码.经过javac编译后形成.class,是字节码文件. ...

  7. 微信小程序又一爆炸功能上线-云开发

    云开发介绍 开发者可以使用云开发开发微信小程序.小游戏,无需搭建服务器,即可使用云端能力. 云开发为开发者提供完整的云端支持,弱化后端和运维概念,无需搭建服务器,使用平台提供的 API 进行核心业务开 ...

  8. 从C++起步到MFC实战VC++软件工程师高端培训 视频保存在 播音员的网盘中

    从C++起步到MFC实战VC++软件工程师高端培训(服务器端开发方向)[共332课时]视频保存在 播音员的网盘中http://www.it1352.com/VideoTutorial/Details? ...

  9. js 关系运算符

    1.大于  >   (小于 效果一样) > //true > //false //false,如果有一个字符串,字符串转换成数值在比较 ' //true,如果两个都是字符串,则比较第 ...

  10. TP5.1:模板继承(重要知识点)

    1.在app\index\controller文件夹新建一个名为Lyot(自定义)的控制器,在控制器中定义: 2.创建一个被继承的public(自定义)文件夹,里面有三个文件,分别是header.ht ...