Skip to content

Instantly share code, notes, and snippets.

@vis97c
Created October 23, 2025 20:37
Show Gist options
  • Select an option

  • Save vis97c/1936fb29ff8710b1717c3e858eb110ad to your computer and use it in GitHub Desktop.

Select an option

Save vis97c/1936fb29ff8710b1717c3e858eb110ad to your computer and use it in GitHub Desktop.
Algoritmos
# input ejemplo
# 7
# -7 -8 5 2 + 1 8 -18 1
# 6 -4 8 -6 1 + 2 -8 1
# -8 1 4 -6 2 + 0 -36 0 -49 0 1
# -53 -72 -1 6 1 + 10 -25 1
# -29 -72 -60 -1 1 + -9 3 4 -8 1
# -69 4 -45 -56 3 2 + -33 -27 -28 -54 -31 -10 1
# -29 6 -87 -15 2 + -54 -2 -90 2
# output
# 5
# 6
# 7
# 4
# 9
# 12
# 14
def divisor(valores):
primer=valores.pop()
valores=valores[::-1]
negative=True
candidato=2
# Probemos divisores candidatos (c)
while (negative):
anterior=primer
listado=[primer]
funco=True
for valor in valores:
anterior = (anterior*candidato)+valor
listado.append(anterior)
if anterior < 0:
# saltar a siguiente candidato
funco=False
break
if not funco:
candidato+=1
continue
# Si funco
negative=False
return candidato
filas = int(input())
for x in range(filas):
A, B = input().split(' + ')
# Remapear
A = A.split()
B = B.split()
lenA = len(A)
lenB = len(B)
A_plus_B = []
terminos = lenA if lenA >= lenB else lenB
# Sumar polinomio
for i in range(terminos):
if lenA >= lenB:
primeroA = int(A[i])
if i < lenB:
primeroB = int(B[i])
A_plus_B.append(primeroA + primeroB)
else:
A_plus_B.append(primeroA)
else:
primeroB = int(B[i])
if i < lenA:
primeroA = int(A[i])
A_plus_B.append(primeroA + primeroB)
else:
A_plus_B.append(primeroB)
# print(A_plus_B)
print(divisor(A_plus_B))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment