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 ;
}

【Aizu - 0005 】GCD and LCM的更多相关文章

  1. 【51nod 2026】Gcd and Lcm

    题目 已知 \(f(x)=\sum_{d|x}μ(d)∗d\) 现在请求出下面式子的值 \(\sum_{i=1}^{n}\sum_{j=1}^{n}f(gcd(i,j))∗f(lcm(i,j))\) ...

  2. 【CF#338D】GCD Table

    [题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证g ...

  3. 【BZOJ 2818】 GCD

    [题目链接] 点击打开链接 [算法] 线性筛出不大于N的所有素数,枚举gcd(x,y)(设为p),问题转化为求(x,y)=p的个数          设x=x'p, y=y'p,那么有(x,y)=1且 ...

  4. 【Codeforces 582A】 GCD Table

    [题目链接] 点击打开链接 [算法] G中最大的数一定也是a中最大的数.          G中次大的数一定也是a中次大的数. 第三.第四可能是由最大和次大的gcd产生的 那么就不难想到下面的算法: ...

  5. 【HDU 5382】 GCD?LCM! (数论、积性函数)

    GCD?LCM! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  6. 【51nod2026】Gcd and Lcm(杜教筛)

    题目传送门:51nod 我们可以先观察一下这个$f(x)=\sum_{d|x}\mu(d) \cdot d$. 首先它是个积性函数,并且$f(p^k)=1-p \ (k>0)$,这说明函数$f( ...

  7. 【poj 2429】GCD & LCM Inverse (Miller-Rabin素数测试和Pollard_Rho_因数分解)

    本题涉及的算法个人无法完全理解,在此提供两个比较好的参考. 原理 (后来又看了一下,其实这篇文章问题还是有的……有时间再搜集一下资料) 代码实现 #include <algorithm> ...

  8. 【Codeforces 582A】GCD Table

    [链接] 我是链接,点我呀:) [题意] 给你一个数组A[]经过a[i][j] = gcd(A[i],A[j])的规则生成的二维数组 让你求出原数组A [题解] 我们假设原数组是A 然后让A数组满足A ...

  9. 【UVA 11426】gcd之和 (改编)

    题面 \(\sum_{i=1}^{n}\sum_{j=1}^m\gcd(i,j)\mod998244353\) \(n,m<=10^7\) Sol 简单的一道莫比乌斯反演题 \(原式=\sum_ ...

随机推荐

  1. Java操作XML牛逼利器JDOM&DOM4J

    JDOM  JDOM 是一种使用 XML(标准通用标记语言下的一个子集) 的独特 Java 工具包,用于快速开发 XML 应用 程序. JDOM 官方网站:http://www.jdom.org/ 利 ...

  2. HDU 5360 【优先队列+贪心】

    题意: 给定N个无序区间. 对合法区间的定义是: 在这个区间之前已经选出了至少l个合法区间,最多选出了r个合法区间.则该区间为合法区间. 输出最多能挑选出多少个合法区间,并输出合法区间的数量. 思路: ...

  3. Java的方法

    以下内容引用自http://wiki.jikexueyuan.com/project/java/methods.html: 一个Java方法是为了执行某个操作的一些语句的组合.举个例子来说,当调用Sy ...

  4. CSS 空中飘动的云动画

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. ExpandableListView的使用以及信息的高亮显示

    ExpandableListView是ListView控件的延伸,它能够对数据进行分组显示和隐藏,并统计总数量.可进行滚动,对某一内容高亮显示. <1>编写xml布局文件,用于获取Expa ...

  6. HDU 5089 Assignment(rmq+二分 或 单调队列)

    Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  7. 深刻理解Java中形參与实參,引用与对象的关系

    声明:本博客为原创博客,未经同意.不得转载! 原文链接为http://blog.csdn.net/bettarwang/article/details/30989755 我们都知道.在Java中,除了 ...

  8. 鸟哥的Linux私房菜-----12、学习使用Shell scripts

  9. redis缓存数据库的详解

    1,什么是redis? Redis是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库 Redis与其他key-value缓存产品有以下三个特点: Redis支持数据的持久化,可以 ...

  10. What's the difference between jquery.js and jquery.min.js?

    They are both the same functionally but the .min one has all unnecessary characters removed in order ...