AOJ 0005 GCD and LCM
题意:求两数最大公约数和最小公倍数。
类型:辗转相除法
算法: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的更多相关文章
- 【Aizu - 0005 】GCD and LCM
GCD and LCM Descriptions: Write a program which computes the greatest common divisor (GCD) and the l ...
- HDOJ 4497 GCD and LCM
组合数学 GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- 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 ...
- GCD 与 LCM UVA - 11388
题目链接: https://cn.vjudge.net/problem/23709/origin 本题其实有坑 数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的 思路是最大公因数的倍 ...
- 简单数论总结1——gcd与lcm
并不重要的前言 最近学习了一些数论知识,但是自己都不懂自己到底学了些什么qwq,在这里把知识一并总结起来. 也不是很难的gcd和lcm 显而易见的结论: 为什么呢? 根据唯一分解定理: a和b都可被分 ...
- poj 2429 GCD & LCM Inverse 【java】+【数学】
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9928 Accepted: ...
- HDU 4497 GCD and LCM (合数分解)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- hdu4497 GCD and LCM
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total S ...
- HDU 4497 GCD and LCM(数论+容斥原理)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
随机推荐
- HDU - 3564 Another LIS(LIS+线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意 给出1~n的插入顺序,要求每次插入之后的LIS 分析 首先用线段树还原出最终序列.因为插入的顺序是按 ...
- UVALive - 7637 E - Balanced String(构造)
原题链接 题意:给出一个打乱顺序的序列,问是否能构造出一个括号匹配的字符串.每个数字为此前读取到的左括号数减去右括号数. 分析:有左括号开始构造,不够的话就找右括号.注意特殊情况待处理.详情看代码 # ...
- js定时器整理(执行一次、重复执行)
在javascritp中,有两个关于定时器的专用函数,分别为: 1.倒计定时器:timename=setTimeout("function();",delaytime); 2.循环 ...
- buildroot构建项目(八)--- u-boot 2017.11 适配开发板修改 5 ---- 系统启动初始化之五
执行完 board_init_f 后,跳回到 crt0.S中继续执行汇编语言 ldr r0, [r9, #GD_START_ADDR_SP] /* sp = gd->start_addr_sp, ...
- luogu 2294 狡猾的商人 带权并查集
此题做法多啊 带权并查集,区间dp,前缀和,差分约束 1.自己写的前缀和, 11 #include<bits/stdc++.h> #define rep(i,x,y) for(regist ...
- SpringMVC上传文件的三种方式(待整理...)
参考链接 http://www.cnblogs.com/fjsnail/p/3491033.html
- 数组Array的一些方法
数组对象属性和方法的概述:1> arr.push() 将参数添加至数组的末尾,返回的是新数组的长度2> arr.unshift() 将参数添加到数组的开头,返回新数组的长度3> ar ...
- VS2013+Win10+opencv3.0配置(包括opencv2.4.10版本)
在win下配置opencv3.0.0还是比较简单的,这里简单说一下配置过程:参考链接:http://blog.csdn.net/u010009145/article/details/50756751 ...
- AF_INET域与AF_UNIX域socket通信原理对比【转】
转自:https://www.cnblogs.com/lfxiao/p/9672797.html 1. AF_INET域socket通信过程 典型的TCP/IP四层模型的通信过程. 发送方.接收方依 ...
- malloc()函数(Linux程序员手册)及函数的正确使用【转】
转自:https://blog.csdn.net/david_xtd/article/details/7311204 名称 malloc,free,calloc,realloc--分配和释放动态内存 ...