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. Sublime Text Emmet插件 : 生成html,css 快捷键

    (输入下面简写,按Tab键可触发效果,或者 ctrl + e) html缩写 输入 !后 按下 ctrl + e : 结果 <!DOCTYPE html><html lang=&qu ...

  2. HTML5制作新年贺春

    <!DOCTYPE html> <html> <head> <meta charset='UTF-8'/> <meta name='viewpor ...

  3. ASP.NET与json对象互转

    这两天写这个xml跟json的读写,心累啊,也不是很理解,请大家多指教 首先来个热身菜做一个简单的解析json 在script里写一个简单的弹窗效果 <script> //script里简 ...

  4. MySQL免安装版中 my-default.ini 的配置

    拷贝一份  “my-default.ini”  文件 重命名为 “my.ini” 这样根目录下就有两个.ini文件了 一个是my-default.ini 一个是my.ini 接下来我们只需修改my.i ...

  5. TP5.1:数据库的增删改查操作(基于数据库操作)

    1.在app/index/controller文件夹下创建一个文件,名为:Operation 注意:起名一定要避开关键字,例如:mysql,curd等等,如果使用关键字起名,会造成报错! 在Opera ...

  6. MySQL入门很简单: 8查询数据

    1. 查询语句语法 SELECT 属性列表 FROM 表名和视图列表 [WHERE 条件表达式1] [GROUP BY 属性名1 [HAVING t条件表达式2]] [ORDER BY 属性名2 [A ...

  7. 2018.7.19 . php复习

    PHP程序设计 1.请写出HTML标记meta的完整英文单词:metadata 2.相当于http文件头作用(向浏览器传回正确和精确地显示网页内容的消息)的meta标记的属性是http-equiv 3 ...

  8. tcp 的编程例子

    https://www.cnblogs.com/ylllove/p/6852125.html

  9. IntelliJ IDEA / Eclipse 自动生成 Author 注释 签名

    Author 注释 签名如下: /*** @author 稚枭天卓 E-mail:zhxiaotianzhuo@163.com* @version 创建时间:2016-6-20 下午04:58:52* ...

  10. jQuery与Aiax应用

    Ajax(一部JavaScript和XML) 优势: ①不需要插件支持 ②优秀的用户体验:能在不刷新整个页面的前提下更新数据,这使得web应用程序能更为迅速地回应用户的操作. ③提高web程序的性能: ...