백준 문제풀이

baekjoon - python - 1735

winston1214 2020. 11. 24. 22:57
반응형

www.acmicpc.net/problem/1735

 

1735번: 분수 합

첫째 줄과 둘째 줄에, 각 분수의 분자와 분모를 뜻하는 두 개의 자연수가 순서대로 주어진다. 입력되는 네 자연수는 모두 30,000 이하이다.

www.acmicpc.net

 

# @Author YoungMinKim
# baekjoon

import sys
from math import gcd
A1,A2 = map(int,sys.stdin.readline().split())
B1,B2 = map(int,sys.stdin.readline().split())
mom = A2*B2
child = B2*A1 + A2*B1
if gcd(mom,child) != 1:
    mom2 = mom // gcd(mom,child)
    child2 = child//gcd(mom,child)
    print(child2,mom2)
else:print(child,mom)

 

반응형