Find all positive integers $n$ for which

a) $7^{399} \mid n!$, but $7^{400} \nmid n!$, and

b) $7^{400} \mid n!$, but $7^{401} \nmid n!$.
Solution. For a given positive integer $n$, let $f(n)$ denote the exponent of 7 in the prime factorization of $n!$. Our task is to solve the equations a) $f(n)=399$; b) $f(n)=400$.

If we multiply two numbers, the exponents of 7 in their prime factorizations add up. Therefore, $f(n)$ can also be calculated by summing the exponents of 7 in the prime factorizations of the first $n$ numbers. This can also be done by counting each number from 1 to $n$ as many times as the exponent of 7 in its prime factorization.

First, consider all numbers divisible by 7. Their count is: $\left[\frac{n}{7}\right]$. At this point, we have only counted 1 from each exponent. However, in numbers divisible by $7^2$, the exponent of 7 is at least 2, so we need to add the count of these numbers, $\left[\frac{n}{7^2}\right]$, to the previous value. Then, in numbers divisible by $7^3$, we still haven't counted the "third" 7, so we also need to add $\left[\frac{n}{7^3}\right]$ and so on. With this method,

$$
f(n)=\left[\frac{n}{7}\right]+\left[\frac{n}{7^2}\right]+\left[\frac{n}{7^3}\right]+\ldots
$$

where the infinite sum has only finitely many non-zero terms.

Due to the integer part, we cannot directly approach the equations. Using the fact that $f(n)$ is monotonically increasing, we can solve the equations with approximations and some trial and error. The monotonicity ensures that the equation has no more than one solution.

It is clear that

$$
f(n)=\left[\frac{n}{7}\right]+\left[\frac{n}{7^2}\right]+\left[\frac{n}{7^3}\right]+\ldots \leq \frac{n}{7}+\frac{n}{7^2}+\frac{n}{7^3}+\ldots=\frac{1}{7} \cdot \frac{n}{1-\frac{1}{7}}=\frac{n}{6}
$$

(By the formula for the sum of a geometric series.)

It is also clear that $f(n)$ does not deviate significantly from this value, so since the value of $f(n)$ in both equations is around 400, we look for the value of $n$ around $6 \cdot 400 = 2400$.

$$
f(2400)=\left[\frac{2400}{7}\right]+\left[\frac{2400}{7^2}\right]+\left[\frac{2400}{7^3}\right]+\ldots=342+48+6+0+0+\ldots=396
$$

This is too little for both the a) and b) cases. Since $f(n)$ is monotonically increasing, we choose a value of $n$ that is 1 greater:

$$
\begin{aligned}
f(2401) & =\left[\frac{2401}{7}\right]+\left[\frac{2401}{7^2}\right]+\left[\frac{2401}{7^3}\right]+\left[\frac{2401}{7^4}\right]+\ldots= \\
& =343+49+7+1+0+0+\ldots=400
\end{aligned}
$$

In the a) case, this is already too much, but in the b) case, it is exactly right. Due to the monotonicity, there is no solution in the a) case. In the b) case, 2401 is the smallest solution. If we increase the value of $n$ one by one, the value of $f(n)$ only increases at numbers divisible by 7, and remains constant between two consecutive numbers divisible by 7. The next number divisible by 7 after 2401 is 2408, so the solutions to the b) equation are the integers in the range $[2401; 2407]$. The monotonicity ensures that there are no more solutions.

In summary:

a) no solution
b) $n \in \{2401; 2402; \ldots; 2407\}$.