![]() |
VOOZH | about |
Given an integer N, the task is to print prime factors of N in decreasing order using the stack data structure.
Examples:
Input: N = 34
Output:
17 2
Explanation:
The prime factors of the number 34 is 2 and 17.Input: N = 8
Output: 2
Approach: The idea is to use the Stack data structure to store all the prime factors of N and in the end, print all the values in the Stack. Follow the steps below to solve the problem:
Below is the implementation of the above approach:
2
Time Complexity: O(sqrt(N))
Auxiliary Space: O(1)