I am looking for a formula, algorithm, or even literature on the topic.
Take $21$ for example
$21 = 7 \cdot 3$
What is the order of $3^{x} \bmod 21$?
$3^0 = 1$
$3^1 = 3$
$3^2 = 9$
$3^3 = 6$
$3^4 = 18$
$3^5 = 12 $
$3^6 = 15$
$3^7 = 3$
Therefore the order of $3^x \mod 21$ is $6 (3,9,6,18,12,15)$
Is there a formula or algorithm for solving order$(p,n)$?