Given that there are $24$ primes between $3$ and $100$, inclusive, what is the number of ordered pairs $(p, a)$ with $p$ prime, $3\le p<100$, and $1\le a < p$ such that the sum $a+a^2+a^3+ \cdots + a^{(p-2)!}$ is not divisible by $p$?
If $a = 1$, then the sum just becomes $(p-2)!$, which is never divisible by $p$. So since there are $24$ odd primes between 2 and 100, there are $24$ solutions of the form $(p, 1)$.
Next, suppose $a \ne 1$. The sum can then be written as $$a + a^2 +\cdots + a^{(p-2)!} = a\times\frac{a^{(p-2)!}-1}{a-1} =\frac{a}{a-1}\cdot \left(a^{(p-2)!}-1\right)$$
Since $1 < a < p$, the term $\frac{a}{(a-1)}$ does not contribute to whether the sum is divisible by $p$. So it sufficient to consider the term $a^{(p-2)!}-1$. Now look at the following cases.
- If $p = 3$, then the sum is just $a$ which is not divisible by $p$. So $(3, 2)$ is a valid solution.
- If $p = 5$, then the sum is $$\frac{a}{a-1}\cdot (a^6-1) \equiv \frac{a}{a-1}\cdot(a^2 -1) \equiv a(a + 1) \pmod{5}$$ by Fermat's Little Theorem. Plugging in $a = 2, 3, 4$ shows that $(5, 2)$ and $(5, 3)$ are the only solutions here.
- If $p > 5$, then $2 \ne (p-1)/2$. Moreover, we also have $2 \mid (p-2)!$ and $(p-1)/2 \mid (p-2)!/2$ since $1 < 2, (p - 1)/2 < p - 2$. Thus $(p - 1) \mid (p - 2)!$, so by Fermat's Little Theorem $a^{(p-2)!}-1\equiv \pmod{p}$. Thus the sum is always divisible by $p$ in this case, and there are no solutions here.
Thus there is a total of $\boxed{27}$ solutions.