2

Like in title. I need to solve this equation: $$1=91p+74q$$ with $p, q$ being integers. I brute forced the solution to be $(p,q)=(-13,16)$, but I'd love to know how to solve it without just mashing keys on the calculator, hoping for the best.

Neat Math
  • 4,790

4 Answers4

5

Use the extended Euclidean algorithm.

$91=1\cdot74+17$

$74=4\cdot17+6$

$17=2\cdot6+5$

$6=1\cdot5+1$.

Therefore,

$1=6-1\cdot5=6-1(17-2\cdot6)=3\cdot6-17=3(74-4\cdot17)-17=3\cdot74-13\cdot17$

$=3\cdot74-13(91-74)=16\cdot74-13\cdot91$.

J. W. Tanner
  • 60,406
2

Use the forward version of the Extended Euclidean Algorithm:

$$\begin{array}{ccl} & 91 & 74\\ --- & --- & --- & ----\\ 91 & 1 & 0 & (1) \\ 74 & 0 & 1 & (2) \\ 17 & 1 & -1 & (3) = (1)-(2)\\ 6 & -4 & 5 & (4) = (2)-4\times(3)\\ -1 & 13 & - 16 & (5) = (3)-3\times(4) \end{array}$$

Therefore $-1 = 13(91)-16(74) \implies 1=(-13)\times 91+16\times (74)$

Note: when I did regular EEA it's very easy to make calculation mistake because of its backward substitution nature. With this forward method it almost never happened. And when it does, you can track each line easily to find where you made a mistake. For example,

Line $(1): 91 = 1\times 91 + 0 \times 74$

Line $(4): 6 = -4 \times 91 + 5 \times 74$

etc.

Neat Math
  • 4,790
1

I see that others have mentioned the Euclidean Algorithm. That would surely work. I would like nominate an approach I constantly use.

So we first look at $91$ and $74$. They are coprime, which means that such $p,q$ exist. What we want to do is to write $1$ as a linear combination of $91$ and $74$ with integer coefficients. We have $91-74=17$, so $17$ can be written as a linear combination of $91$ and $74$ with integer coefficients (which are $1$ and $-1$). Next we want to find a even smaller number that can also be written as a linear combination. We have $91-5\cdot 17=6$. Now we have $91-15\cdot 6=1$, i.e.,

$$1=91-15\cdot 6=91-15\cdot(91-5\cdot 17)=91-15\cdot(91-5\cdot(91-74))\\=91-15\cdot(5\cdot 74-4\cdot 91)=61\cdot 91-75\cdot 74$$

  • 1
    I don't see a significant difference between the math that you have displayed and the math in the answer of J. W. Tanner. His answer focused on the critical numbers, $17$ and $6$. So does yours. Can you demonstrate that in general, your method will be more efficient than the orderly attack inherent in the Extended Euclidean Algorithm? – user2661923 Jan 08 '21 at 18:14
  • @user2661923 We can actually make the math different. For example, after $17$, we have $-74+5\cdot 17=11$ and then $-74+7\cdot 11=3$ and then $-74+25\cdot 3=1$. This method may not be more efficient in general, I think. It's just I'm more comfortable with this one. – Yuqiao Huang Jan 08 '21 at 18:30
  • If I'm not mistaken, what you are focusing on is called the Least-remainder Algorithm. This variation will certainly (in general) be more efficient. However, when responding to a (new) user's corresponding query, it is best to keep things simple. – user2661923 Jan 08 '21 at 18:39
  • @user2661923 Thank you for the information! I didn't know that. And thank you for your advice. – Yuqiao Huang Jan 08 '21 at 18:45
  • @user2661923 There is in fact a significant difference, viz.. the answer appears to be using Gauss's algorithm in equation (vs. fraction form). This will always work for a prime modulus, but may fail for a composite modulus. – Bill Dubuque Jan 08 '21 at 22:19
  • If the answer is not using that but instead is arbitrarily choosing which pair of numbers to reduce then at the end you need to ensure that all the numbers in the sequence are divisible by the last one (we can keep track of which numbers need to be checked - in the classical algorithm it is only the prior number, so no others need checking). More generally see Hermite(-Smith) normal form algorithms. – Bill Dubuque Jan 08 '21 at 22:22
  • @BillDubuque Interesting Pandora's Box. Skimming your links, it looks like Gauss' algorithm requires that for $b$ co-prime to $m$, you happen to know $b^{(-1)}\pmod{m}.$ Ironically, one of the applications of the Euclidean Algorithm is :given $b$ coprime to $a$, calculate $b^{(-1)}\pmod{a}.$ Therefore, one might question the appropriateness of attempting to incorporate Gauss' algorithm in a general algorithm that is designed to solve $ax + by = 1.$ Have I misunderstood something? – user2661923 Jan 08 '21 at 22:39
  • @user2661923 If you read more closely you will learn that Gauss's algorithm was designed to compute modular inverses (which is equivalent to solving the associated linear diophantine equation). – Bill Dubuque Jan 08 '21 at 22:45
  • Very interesting, I must have missed this, thanks. – user2661923 Jan 08 '21 at 23:40
1

I am going to tell you a very beautiful approach to solve these types of problems note that general solution is x=-13+74t and y=16-91t where t is a nonnegative integer now I tell you how I get that I assume that you know a little bit about continued fractions since I will apply it here now just write 91/74 as a continued fraction now look at the second last convergent say p(n-1) /q(n-1) now use cassini identity which says that p(n) q(n-1) -q(n) p(n-1) =${-1}^n$ by using this I got general solution I hope it helps