Блог пользователя RHandarov

Автор RHandarov, история, 6 лет назад, По-английски

Hi Codeforces, I have a problem where the solution is to solve diofant equation with K unknowns and K > 2. For example one equation of this type is: a1 * x + a2 * y + a3 * z = n and I have to find one solution of x, y and z. It is guaranteed that the equation always have a solution. Are there any algorithm that solve this problem? I will be thankful for helping :)

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Reduce it to the equation with 2 variables

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

A condition for a solution to exist: gcd(a1, a2, a3) divides n.

Now, if we rewrite the equation as: a1 * x + a2 * y = n - a3 * z, using the condition above, it shouldn't be hard to find z such that gcd(a1, a2) divides n - a3 * z. When you manage to do that, just solve the regular Diophantine equation left.