It's easy to count the number of monic polynomials of degree $n$ over $F_q$ without repeated roots using the following code (e.g., q = 3, n = 4):
sage: q = 3
....: n = 4
....: R.<x> = PolynomialRing(GF(q))
....: cnt = 0
....: for i in R.polynomials(of_degree = n):
....: if i.is_monic() and gcd(i, i.derivative()) == 1:
....: cnt += 1
....:
....: print(cnt)
....:
....:
54
However, I'd like to know how to use a formula to count this number. I'd really appreciate it if anyone could help.