Solving equations with given restrictions