The totient function \(\phi(n)\) is the count of numbers from \(1\) to \(n\) that are relatively prime with \(n\), that is, have no common divisors with \(n\) except \(1\). For example, 1, 5, 7, and 11 are relatively prime with 12, while 2, 3, 4, 6, 8, 9, and 10 have a common divisor with 12, so \(\phi(12)=4\). This function was introduced by Leonhard Euler (1707-1783), one of the greatest mathematicians of all times. It is used in number theory and in certain algorithms. The totient function is traditionally written using the Greek letter \(\phi\) (phi).
Euler also described a simple way to calculate \(\phi(n)\). As we know, any integer \(n \gt 1\) can be represented as the product of distinct prime factors, raised to the appropriate powers. For example, \(12=2\cdot 2 \cdot 3=2^2 \cdot 3^1\) and \(200 = 2 \cdot 2 \cdot 2 \cdot 5 \cdot 5 = 2^3 \cdot 5^2\). Euler proved that if \(n=p_1^{e_1} \cdot p_2^{e_2} \dots p_k^{e_k}\), then \(\phi(n) = (p_1-1)p_1^{e_1-1} \cdot (p_2-1)p_2^{e_2-1} \dots (p_k-1)p_k^{e_k-1}\). For example, \(\phi(12)=(2-1)\cdot 2^1\cdot(3-1)\cdot 3^0=4\) and \(\phi(200)=(2-1)\cdot 2^2 \cdot (5-1)\cdot5^1 = 80\).
In this question you will write two methods that help calculate \(\phi(n)\) using Euler's formula.
Write a method smallestPrimeFactor(int n) that returns the smallest prime factor of . Note that the smallest prime factor of n is simply the smallest integer greater than or equal to 2 that divides n.
Complete the method smallestPrimeFactor below.