# Код на ruby 2.2.3p173
def zadanie(jump1, jump2)
min = jump1
for i in 1..1000
next if (i*jump1)%jump2 == 0 or (i*jump2)%jump1 == 0
if min > (i*jump1)%jump2
min = (i*jump1)%jump2
p [min, "#{i} * #{jump1} - #{i*jump1/jump2} * #{jump2}"]
end
if min > (i*jump2)%jump1
min = (i*jump2)%jump1
p [min, "#{i} * #{jump2} - #{i*jump2/jump1} * #{jump1}"]
end
end
return min
end
# # Примеры применения
p zadanie(33, 55)
Вывод
[22, "1 * 55 - 1 * 33"]
[11, "2 * 33 - 1 * 55"]
11
Т.е. минимум при 2 * 33 - 1 * 55 = 11