We aim to show that probability of odd $n>1$ passing the Fermat test for all bases a coprime to n is $$\frac{1}{\phi(n)}\prod_{p|n, p \ prime}gcd(p-1,n-1) $$where $\phi$ is the Euler totient function. We already know that the only numbers that pass are primes and Carmichael numbers, so satisfy
(i)$ \ n$ is square-free
(ii)For all $p|n$, we have $\ p-1|n-1$
The probability that $d|n$ is $1-\frac{1}{n-1}\phi(n-1)$, but other than this I am unsure as to how to go about proving this. Thanks.