Just a few doubts, (I myself had tried to solve this using extended euclidean earlier):
While calling the extended euclidean for the first time, can we write this,
extended_euclidean(d1,-1*d2,&n1,&n2)? Are we allowed to send a negative value to it?
What are things that will change?
If the RHS<0, then the base call needs to be : extended_euclidean(-*d1,d2,&n1,&n2)?
Is there way this could be avoided?
what gcd(a,b) does is check what numbers divides both a and b. Say, a number is divisible by 2, then its obvious negative of that number will also be divisible by 2. So it doesn’t matter you can do your computation with positives of those numbers
you take out the (x,y) u get from extended euclidean, your answer is (n1,n2) = (RHSx + td2)/(gcd(d1,d2) , (RHSy + td1)/(gcd(d1,d2)). Now choose smallest value of t such that n1 and n2 are positives