You are given a positive integer βNβ, your task is to return an array/list of integers such that the sum of Euler Totient Function values of each integer of the array is equal to βNβ.
Euler Totient Function:
In number theory, Euler's totient function counts the positive integers up to a given integer βNβ that is relatively prime to βNβ.
More details about Eulerβs Totient Function can be found here
For Example:For βNβ = 10, if we take the array as 1, 2, 5, 10,
The Euler totient function value of 1 is 1.
The Euler totient function value of 2 is 1.
The Euler totient function value of 5 is 4.
The Euler totient function value of 10 is 4.
So, the summation will be 1 + 1 + 4 + 4 = 10.
Hence this is a valid array for βNβ = 10.
Note:
The solution will be verified by the actual value of the Euler Totient Function of 'N' and the sum of the Euler Totient Function of all the values returned. In the output, only the 'YES' or 'NO' is printed, according to the correctness of the solution.
The first line contains a single integer βTβ, representing the number of test cases.
The first line of each test case contains a single integer βNβ, representing the sum of the Euler Totient Function values of all the elements of the output array.
Output Format:
For each test case, Return all the elements of the array satisfying the condition given in the problem statement.
If there are multiple answers possible print any one of them.
Output for each test case will be printed in a separate line.
Note
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 10^3
Time Limit: 1 sec.
Try to use some property of the Euler Totient Function.
We will use the divisor sum property of the Euler Totient Function to solve the problem. This property states that any positive integer βNβ can be represented as the summation of the Euler Totient Function values of all the divisors of βNβ.
So, now our task is to only find all the divisors of βNβ. We can do it by iterating over 1 to βNβ and storing all the numbers which divide βNβ.
Algorithm:
O(N), where βNβ is the given number.
We have to check every number from 1 till βNβ to find factors. So the time complexity will be O(N).
O(1).
Constant extra space is used.