Aizu:0005-GCD and LCM
GCD and LCM
Time limit 1000 ms
Memory limit 131072 kB
Problem Description
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
Input
Input consists of several data sets. Each data set contains a and b separated by a single space in a line. The input terminates with EOF.
Constraints
0 < a, b ≤ 2,000,000,000
LCM(a, b) ≤ 2,000,000,000
The number of data sets ≤ 50
Output
For each data set, print GCD and LCM separated by a single space in a line.
Sample Input
8 6
50000000 30000000
Output for the Sample Input
2 24
10000000 150000000
解题心得:
- 就是给你两个数,要求输出GCD和LCM。
- 其实就是求个GCD,LCM = a*b/GCD
#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
typedef long long ll;
ll __gcd(ll a,ll b) {
if(b == 0)
return a;
return __gcd(b,a%b);
}
int main() {
ll a,b;
while(scanf("%lld%lld",&a,&b) != EOF){
ll gcd = __gcd(a, b);
ll lcm = a * b / gcd;
printf("%lld %lld\n", gcd, lcm);
}
return 0;
}
Aizu:0005-GCD and LCM的更多相关文章
- AOJ 0005 GCD and LCM
题意:求两数最大公约数和最小公倍数. 类型:辗转相除法 算法:gcd(a,b)=gcd(b,a%b),lcm(a,b)=a*b/gcd(a,b). #include <cstdio> #i ...
- poj 2429 GCD & LCM Inverse 【java】+【数学】
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9928 Accepted: ...
- 【Aizu - 0005 】GCD and LCM
GCD and LCM Descriptions: Write a program which computes the greatest common divisor (GCD) and the l ...
- 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都可被分 ...
- 数论----gcd和lcm
gcd即最大公约数,lcm即最小公倍数. 首先给出a×b=gcd×lcm 证明:令gcd(a,b)=k,a=xk,b=yk,则a×b=x*y*k*k,而lcm=x*y*k,所以a*b=gcd*lcm. ...
- HDU 4497 GCD and LCM (合数分解)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- HDU 4497 GCD and LCM(数论+容斥原理)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
随机推荐
- 刚刚写的一个lua下解释csv的工具。
csvtool = {} function csvtool:csv2table(filename) if type(filename) ~= "string" or filenam ...
- Yii2.0 安装yii2-queue并在Linux启动守护进程监听消息
一.什么是yii2-queue? Yii2-queue是Yii2.0 PHP框架下一个消息队列拓展插件,支持基于DB, Redis, RabbitMQ, AMQP, Beanstalk 和 Gearm ...
- Cholesky分解(Cholesky decomposition / Cholesky )
Cholesky decomposition In linear algebra, the Cholesky decomposition or Cholesky is a decomposition ...
- 同步软件UltraCompare 64位 软件及注册机
软件及注册机下载: https://share.weiyun.com/f09e6243887e374ead1b3a3ab8f611a9 软件官方下载地址: https://www.ultraedit ...
- April 21 2017 Week 16 Friday
Courage is like a muscle. We strengthen it with use. 勇气就像肌肉,越使用越强大. Most often it is true, but somet ...
- POJ-1509 Glass Beads---最小表示法模板
题目链接: https://vjudge.net/problem/POJ-1509 题目大意: 给你一个循环串,然后找到一个位置,使得从这个位置开始的整个串字典序最小. 解题思路: 最小表示法模板 注 ...
- iOS逆向命令集
越狱命令行 破壳: 10.10.215.119 ssh root@10.10.215.119 ssh root@10.10.213.176 CCBMobileBank Fuqianlade-iPhon ...
- 2018.7.30 Oracle的Blog数据库类型读取和存
package com.lanqiao.shopping.test; import java.io.BufferedInputStream; import java.io.BufferedOutput ...
- 物流管理系统(数据库+后台+springMVC+Mybatis+layui)
数据库:mysql create database WBG_logistics; use WBG_logistics; #1管理员表 create table admin( a_id int prim ...
- maven环境、本地仓储配置(下载安装)idea配置maven
在第一步:下载maven 官网地址:http://maven.apache.org/download.cgi 下载后进行解压 解压成功 第二步:环境配置 我的电脑右键->属性->高级系统设 ...