【Aizu - 0005 】GCD and LCM
2024-09-30 17:13:25
GCD and LCM
Descriptions:
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
题目链接:
https://vjudge.net/problem/Aizu-0005
多组输入,就是求这两个数的gcd(最大公约数)和lcm(最小公倍数)
注意数据有点大,保险起见用long long吧
AC代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
if(b==)
return a;
return gcd(b,a%b); //递归求最大公约数
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b; //递归求最小公倍数
}
int main()
{
ll a,b;
while(cin >> a >> b)
{
cout << gcd(a,b)<< " "<<lcm(a,b)<<endl;
}
return ;
}
最新文章
- 原生js+本地储存登录注册
- Android监听应用程序安装和卸载
- HTML常用命名和CSS reset代码【收集总结】
- Discuz! 的编码规范
- 使用SQLite数据库和Access数据库的一些经验总结
- mysql忘记root密码
- java中compareTo和compare方法之比较
- iOS后台如何保持socket长连接和数据传输
- CF下Split的使用
- android 删除文件以及递归删除文件夹
- 如何导出远程oracle数据库中的表结构
- Jenkins在windows上的安装配置
- Python----Windows环境下安装Flask
- nginx把POST转GET请求解决405问题
- springboot情操陶冶-web配置(三)
- 虚拟机安装+配置federa
- flume知识点总结
- Linux设备驱动之Ioctl控制【转】
- 192 Word Frequency
- _event_team