I'm asked to compute the inverse of a polynomial $P=a+b_1X+\cdots+b_nX^n$ in a ring $A=\mathbb{Z}/n\mathbb{Z}[X]$. It is known that $P$ is a unit when $a$ is a unit and the $b_i$'s are nilpotent. The nilpotents form the ideal $b\mathbb{Z}$ where $b$ is the product of the prime divisors of $n$, so the $b_i$'s are multiples of $b$.
Then write $(P-a)=b(\sum c_iX^i)=bQ$, which is nilpotent, and let $m$ be minimal such that $(P-a)^m=0$. We then can compute the inverse of $P$ from there: $(P-a)^{m}=0$ gives $P(P^{m-1}+\cdots+d)=(-a)^{m+1}$.
This gives an algorithm to find the inverse.
However, playing (a lot) with my CAS, it seems that there exists some $r$ such that $P^r=1$ so $P^{r-1}$ is the inverse. Is this true? The unit multiplicative group $(\mathbb{Z}/n\mathbb{Z}[X])^{\times}$ is infinte but a unit generates a cyclic subgroup of order $ What I looked at: since we have the form $P^k=a^k+bR$, then if such an $r$ exists, it is a multiple of the multiplicative order $o(a)$ of $a$ in $\mathbb{Z}/n\mathbb{Z}$, as one needs $a^r=1$. What is not clear is when the coefficients of $R$ should be zero or zero divisors with $b$. The numbers $m\leqslant n$ such that $bm=0$ are in $\frac nb \mathbb{Z}$. Can I get any help on this one? Two examples: For $n=48=2^4\cdot 3$, the nilpotents are $N(A)=6\mathbb{Z}$, nilpotence index of $6$ is $n(6)=4$. The polynomial $P=6X^{2}+6X+5$ is invertible. The multiplicative order of $a=5$ is $o(5)=4$. Then computing the $P^k$'s with $k$ a multiple of $o(a)$, one finds $P^{1\cdot 4}\neq 1$ but $P^{2\cdot 4}=1$ so $P^{7}$ is an inverse. The algorithm is quick to write, more than the previous. For $n=9$, the nilpotents are $N(A)=3\mathbb{Z}$, nilpotence index of $6$ is $n(6)=2$. The polynomial $P=3X^{2}+2$ is invertible. The multiplicative order of $a=2$ is $o(2)=6$. Then computing the $P^k$'s with $k$ a multiple of $o(a)$, one finds that $P^{1\cdot 6}=1$.