P
P
pepl2132018-10-16 14:04:14
Python
pepl213, 2018-10-16 14:04:14

How to solve equation with div without iterating?

There is an equation like:
x - 4(x div 7) = 7
You need to find the minimum value of x. Preferably without busting, tk. 1 <= x <= 2*10^9

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-10-17
@pepl213

If 4 and 7 in the example are two parameters of the equation (a and b, respectively), taking only positive integer values, then without enumeration - easily:

def solve_equation(a,b):   # x - a(x div b) = b
    if a%1 + b%1 != 0:
        raise ValueError('both variables must have integer values')
    if 0 < a < b: x = a + b
    else: x = None
    return x
In the sense that for any a < b the answer is: a + b. For all others, there is no solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question