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

类型:辗转相除法

算法: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. 通过lua栈了解lua与c的交互

    lua是如何执行的 其中分析.执行部分都是c语言实现的. lua与c的关系 lua的虚拟机是用c语言实现的,换句话说一段lua指令最终在执行时都是当作c语言来执行的,lua的global表,函数调用栈 ...

  2. JavaScript遍历对象中所有元素

    操作对象如下,属性名不确定: 遍历方法: var temp = new Array(); for(var i in result.datas[0]){ temp.push(result.datas[0 ...

  3. Hibernate_day01

    一.今天内容介绍 1 web内容回顾 (1)javaee三层结构 (2)mvc思想 2 hibernate概述 3 hibernate入门案例 4 hibernate配置文件 5 hibernate的 ...

  4. Nginx 内核优化

    内核参数的优化示例: /etc/sysctl.conf net.ipv4.tcp_max_tw_buckets = // timewait的数量,默认是180000. net.ipv4.ip_loca ...

  5. JavaScript之小工具之日志log()[兼容]

    function log(){ try{ console.log.apply(console,arguments); }catch(e){ try{ opera.postError.apply(ope ...

  6. luogu P2627 修剪草坪

    传送门 单调队列优化dp板子 表示不大想写详细做法,自己看代码吧qwq (懒) 注意细节,不然就会跟我一样WA4次 // luogu-judger-enable-o2 #include<bits ...

  7. C语言中宏定义(#define)时do{}while(0)

    参考链接: http://www.cnblogs.com/fengc5/p/5083134.html 1.用于宏定义, 在该函数可以调用其它的宏,做其它内容的处理

  8. redis的底层数据机构

    集群架构 参考 https://blog.csdn.net/wcf373722432/article/details/78678504 https://www.cnblogs.com/George19 ...

  9. Java读取Txt封装到对象中——(三)

    JavaBean package bean; public class Question { private String timu; //题干 private String leixing; //类 ...

  10. SpringMVC使用Burlap发布远程服务

    参考这篇文章https://www.cnblogs.com/fanqisoft/p/10283156.html 将提供者配置类中的 @Bean public HessianServiceExporte ...