Diana G.

asked • 08/19/22

Write a method totient that returns \(\phi(n)\).

By convention, \(\phi(1)=1\) . For \(n \geq 2\), you must use Euler's formula \(\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 \(n=p_1^{e_1} \cdot p_2^{e_2} \dots p_k^{e_k}\). Your solution will not receive full credit if you count the number of integers below n that are relatively prime with n by "brute force". Call the smallestPrimeFactor method from Part (a). Assume that it works correctly, regardless of what you wrote in Part (a). Solutions that include code that can be replaced by a call to smallestPrimeFactor will not receive full credit.

Complete the method totient below.


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.