In this article, we study an optimized way to calculate the distinct prime factorization up to n natural number using O O(n*log n) time complexity with pre-computation allowed.
Key Concept: Our idea is to store the Smallest Prime Factor(SPF) for every number. Then to calculate the distinct prime factorization of the given number by dividing the given number recursively with its smallest prime factor till it becomes 1.
To calculate to smallest prime factor for every number we will use the sieve of eratosthenes. In original Sieve, every time we mark a number as not-prime, we store the corresponding smallest prime factor for that number (Refer this article for better understanding).
The implementation for the above method is given below :
- Number which has the maximum number of distinct prime factors in the range M to N
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Distinct Prime Factors of an Array
- Distinct Prime Factors of Array Product
- Sort an array according to the increasing count of distinct Prime Factors
- Check if a number exists having exactly N factors and K prime factors
- Maximum number of prime factors a number can have with exactly x factors
- Common prime factors of two numbers
- Count numbers from range whose prime factors are only 2 and 3
- Count common prime factors of two numbers
- K-Primes (Numbers with k prime factors) in a range
- Count numbers from range whose prime factors are only 2 and 3 using Arrays | Set 2
- Check whether a number has exactly three distinct factors or not
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Queries to find whether a number has exactly four distinct factors or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.