Maths WorkshopMaths problems with full solutions
Exercise 2202Number theory › PrimesM1Added 3 Nov 2026

Stirling's formula and primes

#Stirling#factorial#prime counting

Statement

Use Stirling's formula to estimate the number of primes in the factorials up to n!n!.

Hint

n!∼2πn(n/e)nn!\sim\sqrt{2\pi n}(n/e)^n.

Show solutionHide solution

Solution

Stirling. ln⁡(n!)∼nln⁡n−n\ln(n!)\sim n\ln n-n.

Prime factorization. n!=∏p≤npvp(n!)n!=\prod_{p\le n}p^{v_p(n!)} with vp(n!)=∑k⌊n/pk⌋v_p(n!)=\sum_k\lfloor n/p^k\rfloor.

Estimate. ln⁡(n!)=∑p≤nvp(n!)ln⁡p≈n\ln(n!)=\sum_{p\le n}v_p(n!)\ln p\approx n (leading order), so the total "weight" of primes up to nn contributes about nn in the log.

Conclusion. Stirling is compatible with the prime number theorem: ∑p≤nln⁡p∼n\sum_{p\le n}\ln p\sim n (Chebyshev's θ\theta function).