 Now if we want to do algebra mod n, we have to be able to add, subtract, multiply, and divide. In addition, subtraction and multiplication aren't problems, and division's a little bit more problematic. And the way we handle that is to remember that when we divide by a number, we are multiplying by the multiplicative inverse of that number. Which is to say if I want to divide by 7, for example, I can multiply by 1 over 7 because 1 over 7 times 7 is equal to 1. So we are looking at the problem of finding multiplicative inverses. So let's take a look at a simple example. Find the multiplicative inverse of 7 mod 25. Now what that means is I need to try and solve the equation 7x is congruent to 1 mod 25. And what that corresponds to is a diathontian problem. Well, remember 7x is one more than the multiple of 25. So I can write this as 7x equals 25y plus 1, where I'm looking for positive integers x and y. Now there's a number of different ways that I can solve this problem, but one thing I can do is to proceed as follows. So I have my equation 7x equals 25y plus 1. And because x and y are integers and because I'm dealing with ordinary arithmetic here, note the equals, then what I can do is I can do what I want to do, which is to divide by 7 to get x by itself. Now that doesn't really seem to help us very much, but what I'm going to do is I'm going to split this numerator into two portions. I'm going to split it into a portion that can be divided by 7 and then whatever's left over. So it's going to look something like that. And so I have, again, same denominator, 25y plus 1 over 7. But now this first term here can be reduced. So I'll do that, 21y over 7 becomes 3y. And then because I want x to be an integer, well, 3y is definitely going to be an integer. This thing has to be an integer in order for x to be an integer. Well, I'll give it a name. Let's call 4y plus 1 over 7. We'll call that n. And again, I have a nice algebraic equation among the real numbers. So I can do all of the standard real number algebra techniques. I'll multiply by 7 to convert that into a nice equation. And note that what I have here is very similar to the equation that we started with. Now, there is one crucial distinction. The equation that we started with had the variable with the smaller coefficient on the left, and it was equal to the variable with the larger coefficient plus whatever was left over. Here I have the variable with the larger coefficient equal to the variable with the smaller coefficient. And in order for us to proceed effectively, we're going to want to always solve for the variable with the smaller coefficient. So I'll do a little bit of algebra. I'll rearrange things a little bit for y equals 7n minus 1, and I'm going to proceed as we did before. I'm going to divide by 4, and I'm going to split that fraction into a part that is divisible by 4 and a part that isn't whatever's left over. So that gives me 4n over 4 plus 3n minus 1 over 4, and that first term reduces. And that second term, again, if I want y to be an integer, 3n minus 1 over 4 has to be an integer, and I'll give that a name. And we'll repeat. So again, multiplying both sides by 4, solving for the variable with the smaller coefficient, dividing and splitting the fraction into a part that can be divided by 3 and what's left over. I get my next equation, and once again, if this is supposed to be an integer, then I need this fraction, c plus 1 over 3, to be an integer. I'll give it a name, solve for the variable with the lower coefficient, and at this point, I don't have to divide by anything, or I'm dividing by 1 so I can stop, and now I'm ready to actually solve the equation. Well, let's think about this. What I need to do is I need to find what x is. Well, if I want to know what x is, I need to know what y is. Well, how do I find y? Well, here's how I find y. If I want to know what y is, I need to know what n is. Well, how do you find n? Well, if I want to know n, I need to know z. How do you find z? How do you find u? Well, at this point, u is anything that's going to make this expression an integer, which means that u is going to be some integer, but it doesn't really matter which one. So we can start with the last equation, pick an integer value for u, get z, then find n, then find y, then find x. And as long as our algebra has been done correctly, any integer value of u will give us an integer value of x. So let's try it out. For example, let's say u is equal to 1, so that means that z is going to be 3 times 1 minus 1 is 2. Well, I know what z is, so now I can find n, and I'll substitute that in n is equal to 3. And now that I know what n is, I can find y. So y is n plus 3n minus 1 over 4. Now, the one important note here is that the guarantee that we're doing everything correctly is all of these fractions that we end up with always reduce to integers, which is what they should do. And finally, x substituting in y equals 5 gets me 18. Now, again, we're working mod 25, so if I ended up with something that was larger than 25, I can reduce it by subtracting multiples of 25 to get something that's in the correct range. But x equals 18 is our multiplicative inverse. Well, that's great. That gives us a nice general example to how we might find multiplicative inverses, except sometimes we can't. So for example, let's consider the problem of finding the multiplicative inverse of 14 mod 49. And if I try to do this, I'm going to try to find something which when I multiply by x gives me 1 mod 49 one more than a multiple of 49. So I have my Diavontine equation, and I can try to proceed as we did before. So 14x equals 49y plus 1, and I have the variable with the lower coefficient equal to everything else. So I'll divide by 14, and I'll split the numerator into a part that is divisible by 14 and a part that is not. And simplify. And again, I want x to be an integer, which means that this fractional expression should also reduce to an integer. So I'll give it a name, do some algebra, solve for the variable with the lower coefficient, and then divide. And again, split that fraction into a part that is divisible by 7 and a part that is not. And simplify. And here I run into a problem. I need y to be an integer, but this remaining fraction here can never be an integer value. So y can't be an integer unless z is not an integer, and we can't allow that. So, because negative 1, 7 can never be an integer, there is no solution to this diathontine equation, and 14 does not have a multiplicative inverse mod 49.