최대공약수와 최소공배수

BiBi·2021년 1월 19일
0

코딩테스트연습

목록 보기
40/66
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
using namespace std;

int gcd(int a, int b) {
	int tmp;
	while (b != 0) {
		tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

int main() {
	//freopen("input.txt", "rt", stdin);
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d\n%d", gcd(a, b), lcm(a, b));
	

	return 0;
}
profile
Server Network Engineer

0개의 댓글