-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathratios.py
More file actions
51 lines (29 loc) · 989 Bytes
/
ratios.py
File metadata and controls
51 lines (29 loc) · 989 Bytes
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
import math
import sys
def main():
num_rings = int(input())
x = list(map(int, input().split()))
# print n-1 lines
# each line contains A/B in reduced form
# format: "1/2"
num_teeth_first = x[0]
rotations = []
for i in range (1,num_rings):
GCF = find_GCD(num_teeth_first,x[i])
if (num_teeth_first==x[i]):
rotations.append('1/1')
elif (num_teeth_first>x[i]) and (num_teeth_first%x[i]==0):
rotations.append(str(num_teeth_first//x[i])+'/1')
elif (num_teeth_first>x[i]) and (num_teeth_first%x[i]!=0):
rotations.append(str(num_teeth_first//GCF)+'/'+str(x[i]//GCF))
elif (num_teeth_first<x[i]):
rotations.append(str(num_teeth_first//GCF)+'/'+str(x[i]//GCF))
for rot in rotations:
print(rot)
def find_GCD(a,b):
if (b==0):
return a
else:
return find_GCD(b, a%b)
if __name__ == "__main__":
main()