Let $n=p_1^{a_1}\cdots p_k^{a_k}$ be an odd composite. Then the number of bases $1\le b\le n-1$ for which n is a strong pseudoprime is
$ \left(1 + \frac{2^{k\nu}-1}{2^k-1}\right) \prod_{i=1}^k\gcd\left(n^*,\ p_i^*\right) $
where $v_2(x)$ is the largest e such that $2^e|x-1$ and $\nu$ is the minimum of $v_2(p_i)$ over all the $p_i$, and $x^*$ is the largest odd divisor of $x-1$.
1. What is the analogous formula for pseudoprimes? I've seen it but misplaced the reference.
2. What is the original source of this formula? I've never seen an attribution, it's always stated as folk knowledge. Does it date back to the time of Fermat?
3. Similarly, what is the source of the formula above for strong pseudoprimes?