How to solve Linear Diophantine equations in programming?

前端 未结 2 1649
深忆病人
深忆病人 2021-02-06 18:41

I have read about Linear Diophantine equations such as ax+by=c are called diophantine equations and give an integer solution only if gcd(a,b) divides c

2条回答
  •  迷失自我
    2021-02-06 19:02

    Solving Linear Diophantine equations

    ax + by = c and gcd(a, b) divides c.

    1. Divide a, b and c by gcd(a,b).
    2. Now gcd(a,b) == 1
    3. Find solution to aU + bV = 1 using Extended Euclidean algorithm
    4. Multiply equation by c. Now you have a(Uc) + b (Vc) = c
    5. You found solution x = U*c and y = V * c

提交回复
热议问题