Aizu:0005-GCD and LCM
2024-08-25 01:15:31
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;
}
最新文章
- AX2012单元格显示颜色 displayOption
- 【leetcode】Binary Tree Preorder Traversal (middle)★
- BP(back propagation)反向传播
- codeforces 719B:Anatoly and Cockroaches
- 【转】unity地形插件T4M使用帮助
- JS 防止表单重复提交
- 最大流问题Ford-Fulkerson方法(转)
- Android用户界面 UI组件--自动提示输入框 AutoCompleteTextView和MultiAutoCompleteTextView
- 【(阶乘的质因数分解)算组合数】【TOJ4111】【Binomial efficient】
- matlab GUI之常用对话框(四)-- 输入对话框 inputdlg、目录对话框 uigetdir、列表对话框 listdlg
- rest_framework框架的认识
- PHP中如何给日期加上一个月/天
- python类的成员
- Tomcat笔记:Tomcat的执行流程解析
- Java 在给定路径上创建文件,所在文件夹不存在时,如何正确创建。
- 20170724wdVBA正则表达式提取答案到Excel
- AS3 - 数组元素乱序方法以及效率比较
- python查询mysql以字典返回
- Java基础(十四):泛型
- 【Java----字符串转义与反转义】
热门文章
- Python:Tkinter的GUI设计——物体实时移动
- 添加并发请求PDF到工作流附件
- 【起航计划 009】2015 起航计划 Android APIDemo的魔鬼步伐 08 App->;Activity->;QuickContactsDemo 联系人 ResourceCursorAdapter使用 QuickContactBadge使用
- Docker cgroup.procs no space left on device
- SQL SERVER 下:1、递归查询父分类下的各个子分类。 2、查询每个商品分类中最贵的前两个商品SQL
- IA32的三种地址
- 【BZOJ2127】happiness(网络流)
- 2月4号学习的一个SSM整合项目,第一课
- Java继承和访问修饰符
- How To Secure Nginx with Let&#39;s Encrypt on Ubuntu 14.04