OA. free
Free
MathWorks Core Computer Science Core Computer Science Medium

11.

MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.

(Programming Fundamentals) Diophantine Equations**

For a linear Diophantine equation, ax + by = c. What is the value of x, if a solution exists? (Where a, b, c are not zeros and g = gcd(a,b) )

Pick ONE option

Choose one option.
Show answer & explanation
Answer: D. X = (c/g) * (b/g)^-1 mod (a/g)

The linear Diophantine equation ax + by = c has integer solutions if and only if g = gcd(a, b) divides c. The particular solution for x is derived using the extended Euclidean algorithm: first find g and coefficients such that a*(a/g) + b*(b/g) ≡ 1 (mod perspective), then x ≡ (c/g) * (b/g)^-1 (mod a/g), where (b/g)^-1 is the modular multiplicative inverse of (b/g) modulo (a/g).

Step-by-step Derivation:
Step-by-step derivation:

  1. For ax + by = c to have integer solutions, g = gcd(a,b) must divide c.
  2. Divide the equation by g: (a/g)x + (b/g)y = c/g.
  3. Let a' = a/g, b' = b/g, c' = c/g. Now gcd(a', b') = 1 (coprime).
  4. We need a'x + b'y = c', which means a'x ≡ c' (mod b').
  5. Solving for x: x ≡ c' * (a')^-1 (mod b'), equivalently x ≡ (c/g) * (a/g)^-1 (mod b/g).
  6. However, by rearranging to b'y ≡ -a'x (mod a'), we get y ≡ -c' * (b')^-1 (mod a'), and x ≡ (c/g) * (b/g)^-1 (mod a/g).
  7. The standard form used in computational number theory for finding one particular solution is Option D.