Take $n!$ and find $x$, where $a^x$ is the greatest power of $a$ who divides $n!$
Then find $y$, where $y \equiv \frac{n!}{a^x} \bmod a$
For example,
if $a=3$ and $n=6$ then
$6!=2\times3\times4\times5\times6=3^2\times80 \Rightarrow 3^2\times2 \Rightarrow (x=2, y=2)$.
How to find $x$ and $y$ without a computer or computing sucessives divisions? How can we do a explicit formula to find $x$ and $y$ to express $n!$ in this way in $a$?