VOOZH about

URL: https://www.geeksforgeeks.org/dsa/generate-an-array-having-sum-of-euler-totient-function-of-all-elements-equal-to-n/

⇱ Generate an array having sum of Euler Totient Function of all elements equal to N - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Generate an array having sum of Euler Totient Function of all elements equal to N

Last Updated : 23 Jul, 2025

Given a positive integer N, the task is to generate an array such that the sum of the Euler Totient Function of each element is equal to N.

Examples:

Input: N = 6
Output: 1 6 2 3

Input: N = 12
Output: 1 12 2 6 3 4

Approach: The given problem can be solved based on the divisor sum property of the Euler Totient Function, i.e.,

Below is the implementation of the above approach:


Output: 
1 12 2 6 3 4

 

Time Complexity: O(√N)
Auxiliary Space: O(N)

Comment