![]() |
VOOZH | about |
Given a number n, find all prime factors of n.
Note : Prime number is a natural number greater than 1 that has exactly two factors:1 and itself.
Examples:
Input: n = 18
Output: [2, 3, 3]
Explanation: The prime factorization of 18 is 2×32.Input: n = 25
Output: [5, 5]
Explanation: The prime factorization of 25 is 52.
Table of Content
Step by Step implementation:
2 3 3
Every composite number has at least one prime factor less than or equal to its square root. This property can be proved using a counter statement -
- Let a and b be two factors of n such that a*b = n.
- If both are greater than sqrt(n), a*b > sqrt(n)*sqrt(n), which contradicts the expression a * b = n
Step by Step implementation
2 3 3
Related article: