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

类型:辗转相除法

算法: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. Entry point (0x08000000) points to a Thumb instruction but is not a valid Thumb code pointer.

    1.菜单 project-options-linker-misc controls加入 --entry Reset_Handler --first __Vectors 2.导入startup_stm3 ...

  2. MyBatis全局配置文件MyBatis-config.xml代码

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...

  3. 绕过CDN查看网站真实IP的一些办法

    验证是否存在CDN最简单的办法 通过在线的多地ping,通过每个地区ping的结果得到IP. 看这些IP是否一致,如果都是一样的,极大可能不存在cdn,但不绝对. 如果这些IP大多数都不太一样或者规律 ...

  4. Linux - sort 排序

    -t # 指定排序时所用的栏位分隔字符 -n # 依照数值的大小排序 -r # 以相反的顺序来排序 -f # 排序时,将小写字母视为大写字母 -d # 排序时,处理英文字母.数字及空格字符外,忽略其他 ...

  5. 绘图QPainter-画刷

    Qt提供的画刷风格: Qt.TexturePattern   自定义图像画刷 线性渐变 QLinearGradientPattern QLinearGradient需要传入的参数为需要进行渐变的区域坐 ...

  6. 第19月第2天 cellForItemAtIndexPath 返回空

    1. 动画需要获取当前的 Cell ,下面的调用在 viewDidLoad 中,有时候返回 nil,有时候成功. UICollectionView *cell = (UICollectionView* ...

  7. 第18月第10天 iOS11 uicollectionview

    1. - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollect ...

  8. python线程,pipe管道通信原理

    Pipe管道: * 管道实例化后会产生两个通道,分别交给两个进程* 通过send和recv来交互数据,这是一个双向的管道,child和parent可以互相收发 from multiprocessing ...

  9. SpringBoot集成Dubbo

    (1).新建一个普通Maven项目,用于存放一些公共服务接口及公共的Bean等. 项目: 公共Bean: package cn.coreqi.entities; import java.io.Seri ...

  10. 【转】Python之函数进阶

    [转]Python之函数进阶 本节内容 上一篇中介绍了Python中函数的定义.函数的调用.函数的参数以及变量的作用域等内容,现在来说下函数的一些高级特性: 递归函数 嵌套函数与闭包 匿名函数 高阶函 ...