Baekjoon 1735
분수 합


QUESTION ❔



CODE ⌨️

#include <iostream>

using namespace std;

int A, B, C, D;

int gcd(int x, int y)
{
	if (x < y)
	{
		int temp = x;
		int x = y;
		int y = temp;
	}

	while (true)
	{
		if (x % y == 0) return y;

		int temp = x % y;
		x = y;
		y = temp;
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> A >> B;
	cin >> C >> D;

	int front = A * D + B * C;
	int back = B * D;

	int gcd_num = gcd(front, back);

	cout << front / gcd_num << " " << back / gcd_num << "\n";

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

수학 관련 문제였다. 유클리드 호제법에 대하여 공부하였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.