The problem is 9^{-1}*mod*7 and I know the answer is 4 but I would like a program for it so I can easily find out harder ones as well.

The following finds the modular multiplicative inverse with $T\equiv { A }^{ -1 }(modB)$

```
Prompt A,B
abs(B->B
If A<0
B-remainder(~A,B->A
0->T
1->C
B->R
remainder(A,B->D
While D!=0
int(R/D->Q
C->E
T-QC->C
E->T
D->E
R-QD->D
E->R
End
If R>1
Then
Disp "NO INVERSE
Return
End
If T<0
T+B->T
T
```

You could also use:

```
Prompt A,B
B-sum(cumSum(1=remainder(Aseq(A,A,1,B-1),B
If Ans=B
"NO INVERSE
Ans
```

This code is much smaller, but it is also slower than the extended Euclidean algorithm, only works for B≤1000, and also uses much more RAM during execution.

A little faster…

```
Prompt A, B
cumsum(binomcdf(B-2,0 //list from 1 to B-1
max(Ans*(1=remainder(AAns,B
If not(Ans
"NO INVERSE
Ans
```

But the extended Euclidean algorithm, when optimized, should still be faster than this.

An optimized (for size, and probably fast as well) Extended Euclidean Algorithm was written by Ed H of United-TI in 2010. It is available at this page:

www.cemetech(dot)net/projects/uti/viewtopic.php?t=9235

Starting with A and B,

```
:{1,i,A+Bi
:While imag(Ans(3
:iconj(Ans-imag(Ans)int(real(Ans(3)/imag(Ans(3
:End
:real(Ans
```

Ed H says "You'll end up with a list {X,Y,C} with XA + YB = C, where C is the GCD of A and B."

Then you can return Ans(1), or "NO INVERSE" if Ans(3)≠1.

Are these programs for ti-84? I cannot seem to find the "remainder" function

Did you try pressing [math] and then the right arrow key, and scrolling down to see if remainder( is there?

If remainder isn't there, you can do BfPart(A/B), where A is the first variable used in remainder(, and B is the next one. So for example,

```
remainder(-A,B->A
// would be
BfPart(-A/B
remainder(A,B
// would be
BfPart(A/B
```