Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming Help! Phi Brain: Euler\'s Totient Euler\'s totient function, ot

ID: 3675355 • Letter: J

Question

Java Programming Help!

Phi Brain: Euler's Totient

Euler's totient function, otherwise known as (n), measures the number of positive integers relatively prime to n that are less than n. Two numbers are relatively prime if their gcd is 1. For example: (9) = 6 because 1, 2, 4, 5, 7, and 8 are relatively prime to 9. More information about Euler's totient function can be found at this Wiki page.

Write a function int phi(int n) that takes an integer n as an input and returns (n), and a main() that prompts a user for an integer i, calls the function (i), and prints the result. The upper limit for the inputi is 250000.

The output of your program should look and function like the examples shown below.

n Relatively Prime (n) 2 1 1 3 1,2 2 4 1,3 2 5 1,2,3,4 4 6 1,5 2 7 1,2,3,4,5,6 6 8 1,3,5,7 4 9 1,2,4,5,7,8 6 10 1,3,7,9 4

Explanation / Answer

Please find the required program below : import java.io.*; public class Test { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a positive integer n:"); int n = Integer.parseInt(br.readLine()); System.out.println("Phi(n): "+phi(n)); } public static int phi(int n){ int count = 1; for(int i=2; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote