题意:求两数最大公约数和最小公倍数。

类型:辗转相除法

算法:gcd(a,b)=gcd(b,a%b),lcm(a,b)=a*b/gcd(a,b)。

#include <cstdio>
#include <iostream> using namespace std; int gcd(int a, int b) {
for(int t; t = a % b; a = b, b = t);
return b;
} int main() {
int a, b, g;
long long l;
while(scanf("%d%d", &a, &b) != EOF) {
g = gcd(a, b);
l = 1ll * a * b / g;
printf("%d %lld\n", g, l);
}
return 0;
}

AOJ 0005 GCD and LCM的更多相关文章

  1. 【Aizu - 0005 】GCD and LCM

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

  2. HDOJ 4497 GCD and LCM

    组合数学 GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  3. 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 ...

  4. GCD 与 LCM UVA - 11388

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

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

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

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

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

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

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

  8. hdu4497 GCD and LCM

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

  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. jQuery基础 (一)——样式篇(jQuery选择器)

    一.选择器类型 id选择器 class选择器 元素选择器 层级选择器 全选择器(*选择器) 二.有几种方式可以隐藏一个元素: CSS display的值是none. type="hidden ...

  2. "ls: cannot access sys/class/ieee80211: No such file or directory" .

    1- Do update and upgrade as always. apt-get update && apt-get upgrade && apt-get dis ...

  3. Nginx 日志处理

    . nginx日志统计独立ip的个数: awk '{print $1}' /access.log | sort | uniq | wc -l . 查询访问最多的前10个ip awk . 查看某段时间的 ...

  4. Linux之更改Nginx映射默认根目录

     更改nginx映射默认根目录: 1.打开默认配置文件:sudo  vi /etc/nginx/sites-available/default 2.修改配置:root /var/www/html/xx ...

  5. OOM之类、对象、实例、实体之辨析

    一.场景再现         有一个重要的概念你需要弄明白,那就是“类(class)”和“对象(object)”的区别.我用禅语来解释一下吧:         鱼和三文鱼有什么区别?         ...

  6. dubbo框架原理

    Dubbo提供了三个关键功能:基于接口的远程调用,容错与负载均衡,服务自动注册与发现. Dubbo使得调用远程服务就像调用本地java服务一样简单. https://www.jianshu.com/p ...

  7. 列式数据库~clickhouse 数据同步使用

    一 简介:进一步了解clickhouse二 数据操 1 单机建表 create TABLE aaa (    id UInt32,    uid UInt32,    amount Float64,  ...

  8. Freemarker导出带格式的word的使用

    1.新建一个doc文档

  9. LOJ 3089: 洛谷 P5319: 「BJOI2019」奥术神杖

    题目传送门:LOJ #3089. 题意简述: 有一个长度为 \(n\) 的母串,其中某些位置已固定,另一些位置可以任意填. 同时给定 \(m\) 个小串,第 \(i\) 个为 \(S_i\),所有位置 ...

  10. libevent 和 libev 提高网络应用性能

    构建现代的服务器应用程序需要以某种方法同时接收数百.数千甚至数万个事件,无论它们是内部请求还是网络连接,都要有效地处理它们的操作.有许多解决方 案,但是 libevent 库和 libev 库能够大大 ...