# Sum of Euler Totient Functions obtained for each divisor of N

Given a positive integer N, the task is to find the sum of the Euler Totient Function for all the divisor of the given number N.

Examples:

Input: N = 3
Output: 3
Explanation:
Divisors of 3 are {1, 3}. The Euler totient function for the values 1 and 3 are 1 and 2 respectively.
Therefore, the required sum is 1 + 2 = 3.

Input: N = 6
Output: 6

Naive Approach: The given problem can be solved by finding all the divisors of N and then print the sum of values of the Euler totient function for every divisor as the result.

Time Complexity: O(N * sqrt(N))
Auxiliary Space: O(1)

Efficient Approach: The above approach can also be optimized by using the property of the Euler totient function which states that the sum of all the values of the euler totient function of all the divisors is N.

Therefore, the sum of all values of the Euler totient function of N is the number itself.

Below is the implementation of the above approach:

## C++

 `// C++ program for the above approach`   `#include ` `using` `namespace` `std;`   `// Function to find the sum of Euler` `// Totient Function of divisors of N` `int` `sumOfDivisors(``int` `N)` `{` `    ``// Return the value of N` `    ``return` `N;` `}`   `// Driver Code` `int` `main()` `{` `    ``int` `N = 5;` `    ``cout << sumOfDivisors(N);`   `    ``return` `0;` `}`

## Java

 `// Java program for the above approach` `public` `class` `GFG {`   `    ``// Function to find the sum of Euler` `    ``// Totient Function of divisors of N` `    ``static` `int` `sumOfDivisors(``int` `N)` `    ``{` `        ``// Return the value of N` `        ``return` `N;` `    ``}` `    ``// Driver code` `    ``public` `static` `void` `main(String[] args)` `    ``{` `        ``int` `N = ``5``;` `        ``System.out.println(sumOfDivisors(N));` `    ``}` `}` `// This code is contributed by abhinavjain194`

## Python3

 `# Python3 program for the above approach`   `# Function to find the sum of Euler` `# Totient Function of divisors of N` `def` `sumOfDivisors(N):` `    `  `    ``# Return the value of N` `    ``return` `N`   `# Driver Code` `if` `__name__ ``=``=` `'__main__'``:` `    `  `    ``N ``=` `5` `    `  `    ``print` `(sumOfDivisors(N))`   `# This code is contributed by mohit kumar 29`

## C#

 `// C# program for the above approach` `using` `System;`   `class` `GFG{` `    `  `  ``// Function to find the sum of Euler` `    ``// Totient Function of divisors of N` `    ``static` `int` `sumOfDivisors(``int` `N)` `    ``{` `        ``// Return the value of N` `        ``return` `N;` `    ``}`   `// Driver code` `static` `void` `Main()` `{` `     ``int` `N = 5;` `     ``Console.Write(sumOfDivisors(N));` `    `  `}` `}`   `// This code is contributed by sanjoy_62.`

## Javascript

 ``

Output:

`5`

Time Complexity: O(1)
Auxiliary Space: O(1)

Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!