Given a finite integer field $\mathbb{Z}_p$ with $p>1$, I want to find the multiplicative inverse of an element $a\in\mathbb{Z}_p$ such that $a\cdot\hat{a}=1\colon\hat{a}\in\mathbb{Z}_p$.
First, assuming it exists, we can establish the following congruence:
$$a\cdot\hat{a}\equiv1\pmod{p}$$
Then, isolate the terms at one side to reach a congruence with 0:
$$a\cdot\hat{a}-1\equiv1-1\pmod{p}$$ $$a\cdot\hat{a}-1\equiv0\pmod{p}$$
By definition, we can deduce:
$$p\mid a\cdot\hat{a}-1-0\implies a\cdot\hat{a}-1=p\cdot q+0\enspace\colon q\in\mathbb{Z}$$ $$\hat{a}=\frac{p\cdot q+1}{a}$$
With this, it can be inferred that the quotient $q$ must cause $\frac{p\cdot q+1}{a}\in\mathbb{Z}_p$ to be met, so it is equivalent to express such condition as:
$$q = \min \{ q' \in \mathbb{N} / \frac{p \cdot q' + 1}{a} \in \mathbb{Z}_p \} \implies q = \min \{ q' \in \mathbb{N} : p \cdot q' + 1 \equiv 0 \pmod{a} \}$$
Now, if we define the sequence $s_{q,p,a} = \frac{p \cdot q + 1}{a}, \quad \{s_{q,p}\}_{q \in \mathbb{N}}$ and perform some evaluations starting at $q=0$:
$$s_{q,8,3}=\{1/3, 3, 17/3, 25/3, 11, 41/3, 49/3, 19, 65/3, 73/3, 27, 89/3, 97/3, \ 35, 113/3, 121/3\cdots\}$$ $$s_{q,11,4}=\{1/4, 3, 23/4, 17/2, 45/4, 14, 67/4, 39/2, 89/4, 25, 111/4, 61/2, \ 133/4, 36, 155/4, 83/2\cdots\}$$ $$s_{q,11,5}=\{1/5, 12/5, 23/5, 34/5, 9, 56/5, 67/5, 78/5, 89/5, 20, 111/5, 122/5, \ 133/5, 144/5, 31, 166/5\cdots\}$$ $$s_{q,14,5}=\{1/5, 3, 29/5, 43/5, 57/5, 71/5, 17, 99/5, 113/5, 127/5, 141/5, 31, \ 169/5, 183/5, 197/5, 211/5\cdots\}$$
It is seen that in some cases there holds $q=gcd(p,a)+a\cdot k\colon k\in\mathbb{Z}$, so at this point I have several questions:
- What form must $p,a$ adhere to for $q=gcd(p,a)+a\cdot k\colon k\in\mathbb{Z}$ to hold?
In such cases, the following would be true:
$$\hat{a}=\frac{p\cdot (gcd(p,a)+a\cdot k)+1}{a}$$
So, by an equivalence of the $gcd()$ function:
$$\hat{a}=\frac{p\cdot \left(\frac{\displaystyle|p\cdot a|}{\displaystyle lcm(p,a)}+a\cdot k\right)+1}{a}$$
At this outcome, is there any way to formulate $lcm()$ as a closed form?
- Finally, I would also like to know if a closed form exists that returns the value of $q$ from any $p,a$, and therefore the multiplicative inverse $\hat{a}$.