Given two numbers M and N. The task is to print the number which has the maximum number of distinct prime factors of numbers in range M and N. If there exist multiple numbers, print the smallest one.
Input: a=4, b=10
Number of distinct Prime Factors of 4 is 1
Number of distinct Prime Factors of 5 is 1
Number of distinct Prime Factors of 6 is 2
Number of distinct Prime Factors of 7 is 1
Number of distinct Prime Factors of 8 is 1
Number of distinct Prime Factors of 9 is 1
Number of distinct Prime Factors of 10 is 2
Input: a=100, b=150
The approach is to use Sieve of Erathosthenes. Create a factorCount array to store the the number of distinct prime factors of a number. While marking the number as prime, increment the count of prime factors in its multiples. In the end, get the maximum number stored in the factorCount array which will be the answer.
Below is the implementation of the above approach:
- Number of distinct prime factors of first n natural numbers
- Number with maximum number of prime factors
- Maximum number of unique prime factors
- Super Ugly Number (Number whose prime factors are in given set)
- Check whether a number has exactly three distinct factors or not
- Queries to find whether a number has exactly four distinct factors or not
- Distinct Prime Factors of Array Product
- Prime factors of a big number
- Sum of Factors of a Number using Prime Factorization
- Number of elements with odd factors in given range
- Number of steps to convert to prime factors
- Product of unique prime factors of a number
- Efficient program to print all prime factors of a given number
- K-Primes (Numbers with k prime factors) in a range
- Count number of distinct sum subsets within given range
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m