Given a number N, print all its unique prime factors and their powers in N.
Input: N = 100 Output: 2 2 5 2 Explaination: 100 can be written as 2*2*5*5, where 2 is present two times and so is 5.
Input: N = 3 Output: 3 1 Explaination: 3 itself is a prime.
You do not need to read input or print anything. Your task is to complete the function primeFactors() which takes N as input parameter and returns the prime factors and their powers where each prime factor is followed by its power and then another prime factor-power pair and all the prime factors are sorted in ascending order.
Expected Time Complexity: O(logN)
Expected Auxiliary Space: O(N)
2 ≤ N ≤ 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes