AIZU 0005
GCD and LCM
Time Limit : 1 sec, Memory Limit : 65536 KB
Japanese version is here
GCD and LCM
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b (0 < a, b ≤ 2,000,000,000). You can supporse that LCM(a, b) ≤ 2,000,000,000.
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.
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 水题不解释
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; typedef long long ll; int gcd(int x,int y) {
return y > ? gcd(y,x % y) : x;
}
int main() { int a,b;
while(~scanf("%d%d",&a,&b)) {
printf("%d ",gcd(a,b));
printf("%lld\n",(ll)a / gcd(a,b) * b);
} }
AIZU 0005的更多相关文章
- 【Aizu - 0005 】GCD and LCM
GCD and LCM Descriptions: Write a program which computes the greatest common divisor (GCD) and the l ...
- 【python小练】0005
第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小. 首先,iphone5的分辨率是1136x640. if条件句判断横(纵)向是否大于对应的ipho ...
- python练习册0005
第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小. 本题用了几个os模块的命令, import os from PIL import Image p ...
- Aizu 0525 Osenbei 搜索 A
Aizu 0525 Osenbei https://vjudge.net/problem/Aizu-0525 题目: IOI製菓では,創業以来の伝統の製法で煎餅(せんべい)を焼いている.この伝統の製法 ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- Swift教程_swift常见问题(0005)_完美解决Cannot override 'dealloc'异常
Swift教程_swift常见问题(0001)_CoreData: warning: Unable to load class named 'xxx' for entity 'xxx' Swift教程 ...
- Aizu 2249 & cf 449B
Aizu 2249 & cf 449B 1.Aizu - 2249 选的边肯定是最短路上的. 如果一个点有多个入度,取价值最小的. #include<bits/stdc++.h> ...
- Sliding Window - The Smallest Window II(AIZU) && Leetcode 76
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_B For a given array a1,a2,a3,...,aNa1 ...
- Aizu - 2564 Tree Reconstruction 并查集
Aizu - 2564 Tree Reconstruction 题意:一个有向图,要使得能确定每一条边的权值,要求是每个点的入权和出权相等,问你最少需要确定多少条边 思路:这题好像有一个定理之类的,对 ...
随机推荐
- 在线生成ICO图标、站标
网上一搜有很多,找了两个比较好用的,分别是http://ico.storyren.com/和http://www.ico.la/,前面的那个好像更好点.上传png.jpg.或gif格式的图片,按自己需 ...
- oc常见误区
1.同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2.异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然 ...
- PHP时间戳
strtotime strtotime("Today"); #今天凌晨0点的时间戳 strtotime('now'); #当前时间的时间戳 strtotime ( &quo ...
- linux 网桥的配置与实现
==================================================================================from: http://www.i ...
- 【Qt】QDialog之屏蔽Esc键【转】
简述 Qt中Esc键会在一些控件中默认的进行一些事件的触发,比如:QDialog,按下Esc键窗口消失.大多数情况下,我们不需要这么做,那么就需要对默认事件进行屏蔽. 简述 源码分析 事件过滤器 事件 ...
- apache泛域名的配置
假设我们把服务器架设在:/home/www文件夹下面 我们有应用A和B,对应的文件目录为A:/home/www/testAB:/home/www/testB 设置proxy_module让网站支持泛域 ...
- 【PHP】phpcms 关联连接修复
function _keylinks($txt, $replacenum = '',$link_mode = 1) { $keywords = $this->data['keywords']; ...
- JMS消息头
一个消息对象分为三部分:消息头(Headers),属性(Properties)和消息体(Payload).对于StreamMessage和MapMessage,消息本身就有特定的结构,而对于TextM ...
- Thinkphp常用的方法和技巧(转)
2012年09月26日 Thinkphp 里一些常用方法和技巧的整理,包括常用的快捷键以及在程序开发时用到的一些实用方法,关于快捷键用得不是很熟练,总之,掌握这些方法和技巧,对于我们开发 thinkp ...
- 加载驱动模块时Device or resource busy的解决方法
加载驱动模块时Device or resource busy的解决方法 加载驱动模块时Device or resource busy的解决方法 insmod或modprobe驱动模块时Device o ...