The least common multiple of a set of numbers can be found by means of prime factorization. For the positive integers $1$ through $n$, this prime factorization is $ \mathrm{lcm} \{1,2,3,\ldots,n\} = 2^{k_2}3^{k_3}5^{k_5}7^{k_7}11^{k_{11}} \cdots $ where $k_2$ is the largest power of $2$ found in any prime factorization of $n$ or any smaller positive integer, $k_3$ is the largest power of $3$ found in any of those prime factorizations, and so forth for each prime.
For any prime $p$, clearly $p^k$ is the smallest positive integer with $p^k$ in its prime factorization. That is, if $n$ or any smaller positive integer has $p^k$ as a factor, then $p^k \leq n.$ Conversely, if $p^{k+1}$ is not a divisor of $\mathrm{lcm} \{1,2,3,\ldots,n\}$ then $p^{k+1} > n.$ So to find the correct power $k_p$ of any prime $p$ in the factorization of $\mathrm{lcm} \{1,2,3,\ldots,n\}$ we simply find the largest power of $p$ that is not greater than $n.$
By the way, for $n > 1,$ if $n$ is not itself a power of a prime then all the powers of primes that can be found in $n$ are already found in $1,2,3,\ldots, n-1.$ In that case, $ \mathrm{lcm} \{1,2,3,\ldots,n\} = \mathrm{lcm} \{1,2,3,\ldots,n-1\}. $ But if $n$ is a power of a prime, for example, $n = p^m$ (with $m>0$), then the power of $p$ in the factorization of $\mathrm{lcm} \{1,2,3,\ldots,n\}$ is $m$ whereas the power of $p$ in the factorization of $\mathrm{lcm} \{1,2,3,\ldots,n-1\}$ is $m-1$. All other primes that occur in those factorizations occur with the same powers, so $ \mathrm{lcm} \{1,2,3,\ldots,n\} = p \times \mathrm{lcm} \{1,2,3,\ldots,n-1\}. $
Putting this together, $ f(n) = \begin{cases} p f(n-1) & \text{if $n$ is a power of the prime $p$}\\ f(n-1) & \text{otherwise.} \end{cases} $