Даны две рациональные дроби: a/b и c/d. Сложите их и результат представьте в виде несократимой дроби m/n. Мой код: (согласна, длиноватенько)
a, b, c, d = map(int,input().split())
if a == 0 and c == 0:
print(0)
elif a == 0:
s1 = c
w1 = d
s, w = s1, w1
if s c:
k, h, n1, m1 = a, b, c, d
y, u, i, o = a, b, c, d
r, g = h, m1
if h != m1:
if h r, g = g, r
while r%g != 0:
r = r%g
r, g = g, r
u = int(h/g*m1)
o = u
y = int(u/b)
i = int(o/d)
m2 = y-i
n2 = u
m3, n3 = m2, n2
if m3 m3, n3 = n3, m3
while m3%n3 != 0:
m3 = m3%n3
m3, n3 = n3, m3
m = int(m2/n3)
n = int(n2/n3)
print(-m, n)
else:
p1 = a-c
f1 = d
p, f = p1, f1
if p p, f = f, p
while p%f != 0:
p = p%f
p, f = f, p
m = int(p1/f)
n = int(f1/f)
print(-m, n)
if a k, h, n1, m1 = a, b, c, d
y, u, i, o = a, b, c, d
r, g = h, m1
if h != m1:
if h r, g = g, r
while r%g != 0:
r = r%g
r, g = g, r
u = int(h/g*m1)
o = u
y = int(u/b)
i = int(o/d)
m2 = i-y
n2 = u
m3, n3 = m2, n2
if m3 m3, n3 = n3, m3
while m3%n3 != 0:
m3 = m3%n3
m3, n3 = n3, m3
m = int(m2/n3)
n = int(n2/n3)
print(m, n)
else:
p1 = c-a
f1 = d
p, f = p1, f1
if p p, f = f, p
while p%f != 0:
p = p%f
p, f = f, p
m = int(p1/f)
n = int(f1/f)
print(m, n)
else:
k, h, n1, m1 = a, b, c, d
y, u, i, o = a, b, c, d
r, g = h, m1
if h != m1:
if h r, g = g, r
while r%g != 0:
r = r%g
r, g = g, r
u = int(h/g*m1)
o = u
y = int(u/b)
i = int(o/d)
m2 = y+i
n2 = u
m3, n3 = m2, n2
if m3 m3, n3 = n3, m3
while m3%n3 != 0:
m3 = m3%n3
m3, n3 = n3, m3
m = int(m2/n3)
n = int(n2/n3)
print(m, n)
else:
p1 = a+c
f1 = d
p, f = p1, f1
if p p, f = f, p
while p%f != 0:
p = p%f
p, f = f, p
m = int(p1/f)
n = int(f1/f)
print(m, n)
Я проверяла, все работает, но мне выдают "Частичное решение". Почему? (по времени все заходит)