Given an array arr of n positive integers. Represent every number as its factors (x * y = arr[i]) [Here x or y cannot be 1] till it cannot be further represented as x*y = arr[i]. Print the number of steps required to split it till no further representations are possible.
Input: 4 4 4 Output: 3 Explanation: 1st step 2 2 4 4 . 2nd step 2 2 2 2 4 3rd step 2 2 2 2 2 2 Input: 20 4 Output: 3 Explanation: 1st step 20 2 2 (2*2 = 4) 2nd step 2 10 2 2 (2*10 = 20) 3rd step 2 2 5 2 2, (2*5 = 10)
Approach is to pre calculate the prime factors of every number. Prime factors can be efficiently calculated using Sieve’s implementation which requires N * log N. . We know a number can be represented as a multiplication of its prime factors and we can represent it till its not 1, so 1 is not taken into count, so if the number is other than 1, we count the number of prime factors, and then subtract 1 from it.
Time Complexity: O( n * log n)
This article is contributed by Striver. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Prime factors of a big number
- Sum of Factors of a Number using Prime Factorization
- Number which has the maximum number of distinct prime factors in the range M to N
- Maximum number of unique prime factors
- Product of unique prime factors of a number
- Super Ugly Number (Number whose prime factors are in given set)
- C Program for efficiently print all prime factors of a given number
- Efficient program to print all prime factors of a given number
- Number of distinct prime factors of first n natural numbers
- Java Program for efficiently print all prime factors of a given number
- Number with maximum number of prime factors
- Minimum prime number operations to convert A to B
- Find number of factors of N when location of its two factors whose product is N is given
- Common prime factors of two numbers