Two natural data m and n determine, among all pairs of natural numbers (x, y) such that x < m e y < n, a pair for which the value of the expression x * y - x ** 2 + y is maximum and also calculate this maximum.
I solved the problem like this:
m = int(input("Digite m: "))
n = int(input("Digite n: "))
#m = 2
#n =1
x = 0
y = 0
maximo =0
x_maximo = 0
y_maximo = 0
while x <m and y<n:
for i in range(m):
for j in range(n):
soma = i*j -i**2 +j
print (soma)
if soma > maximo:
maximo = soma
x_maximo = i
y_maximo = j
x +=1
y +=1
print ("O máximo é {} para o par (x,y) = ({},{})". format(maximo,x_maximo,y_maximo))
Apparently, the algorithm is correct but I found the solution is not very elegant. Any suggestions on how to improve it? Any simpler way?