-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumer and denom.py
More file actions
56 lines (46 loc) · 1.46 KB
/
Copy pathnumer and denom.py
File metadata and controls
56 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 문제풀이 순서
# 분모끼리 곱해서 공약수 찾기
# 분자는 분모의 곱
# def solution(numer1, denom1, numer2, denom2):
# answer = []
# denom = denom1 * denom2
# # 8
# # 6
# numer_multiply1 = numer1 * denom2
# # 4
# # 27
# numer_multiply2 = numer2 * denom1
# # 6
# # 2
# for i in range(2, denom + 1):
# #2 3 4 5 6 7 8
# if denom % i == 0 and numer_multiply1 % i == 0 and numer_multiply2 % i == 0:
# # i = 2
# answer.append((numer_multiply1 + numer_multiply2) // i)
# answer.append(denom // i)
# print(answer)
# # [5, 4]
# elif denom % i == 0 and numer_multiply1 % i != 0 and numer_multiply2 % i == 0:
# # i = 2 3 6
# answer.append(numer_multiply1 + numer_multiply2)
# answer.append(denom)
# print(answer)
# # solution(1,2,3,4)
# # solution(9,2,1,3)
# solution(3,4,2,7)
###### gpt가 풀어줌 ####
def solution(numer1, denom1, numer2, denom2):
# 분모끼리 곱하기
denom = denom1 * denom2
# 분자는 분모의 곱으로 나누기
numer = numer1 * denom2 + numer2 * denom1
# 최대공약수 찾기
def find_gcd(x, y):
while(y):
x, y = y, x % y
return x
gcd = find_gcd(numer, denom)
# 분자와 분모를 최대공약수로 나누기
answer = [numer // gcd, denom // gcd]
return answer
print(solution(9,2,1,3))