题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=30390
简单的gcd与lcm题目,ac代码如下:
#include <cstdio> #include <iostream> #include <string> using namespace std; typedef long long int ll; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a%b); //递归的求解 } int main(void) { // freopen("in.txt","r",stdin); ll a, b; while (scanf("%lld%lld", &a, &b) != EOF) { if (a<b) swap(a, b); ll gcd_ = gcd(a, b); ll lcm_ = (a*b) / gcd_; printf("%lld %lld\n", gcd_, lcm_); } return 0; }