Find all the prime factors for the given number
Input : A number // 10
Output : An array // [2, 5]
Logic :
Key here is that we need to check the divisor starting with
2to the square root of the input number.
- Divide the number with
2till the remainder is not0.- If its divisible with
2then2to the primeFactors array.
- If its divisible with
- Divide the number starting with
3till the square root of the input number.- If its divisible with
numberthen add to the primeFactors array.
- If its divisible with
- At the end of the for loop if the number is greater than
2then add thenumberto the primeFactors array.