Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3514
@sushant_a 3459
Prime Factors and their Powers
Medium Accuracy: 62.91% Submissions: 197 Points: 4

Given a number N, print all its unique prime factors and their powers in N.

Example 1:

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.

Eaxmple 2:

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)

Constraints:
2 ≤ N ≤ 104

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?