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

类型:辗转相除法

算法: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. Winform中使用WPF控件并动态读取Xaml

    1.添加新项 2.在构造函数中加入 public partial class UserControl1 : UserControl { public UserControl1() { Initiali ...

  2. Telnet Protocol Specification

    Network Working Group J. Postel Request for Comments: 854 J. Reynolds ISI Obsoletes: NIC 18639 May 1 ...

  3. golang error信息转字符串 x := fmt.Sprintf("%s", err)

    _, _, ch, err := m.ZkConn.ChildrenW(node) if err != nil { x := fmt.Sprintf("%s", err) if s ...

  4. SQL——sql年龄段查询

    select * from 表 p where p.gender <> '男' ) ) select * ) ) 查询出所有年龄在15~49岁的非男性的信息

  5. 20155332 2016-2017-2 《Java程序设计》第8周学习总结

    20155332 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 创建Logger对象 static Logger getLogger(String name ...

  6. Linux TCP 连接数

    查看 TCP 连接数 : 每一个 IP 访问的链接数:head 默认 前10 netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print ...

  7. 下拉框combobox用法&级联餐单

    如果下来内容不用后台取数据,直接写死的话不用url属性,直接用data即可: <input id="orderstate" name="orderstate&quo ...

  8. mysql 案例 ~ pt修复工具的使用

    简介:今天咱们来聊聊PT修复工具pt-table-sync 注意事项:   1 表要有主键或者唯一键   2 针对每一个chunk加的是for update锁   3 修复过程中不能容忍从库延迟 如果 ...

  9. 如何用MoveIt快速搭建机器人运动规划平台?

    MoveIt = RobotGo,翻译成中文就是“机器人,走你!”所以,MoveIt的主要就是一款致力于让机器人能够自主运动及其相关技术的软件,它的所有模块都是围绕着运动规划的实现而设计的. 两个月前 ...

  10. 【工具测试】Acunetix 11-登录后扫描的功能

    1.概要 在测试的过程中,会给一些只有登录口的测试站点,只有登录后才能访问更多的页面. Acunetix 11的登录后扫描功能摸索了老半天,原来这么神奇.学习了! 2.操作 登录之后 - [Add T ...