Given a number N which is prime. The task is to find all the numbers less than or equal to 10^6 whose minimum prime factor is N.
Input: N = 2 Output: 500000 Input: N = 3 Output: 166667
Approach: Use sieve of Eratosthenes to find the solution of the problem. Store all the prime numbers less than 10^6 . Form another sieve which will store the count of all the numbers whose minimum prime factor is the index of the sieve. Then display the count of the prime number N (i.e. sieve_count[n]+1), where n is the prime number .
Below is the implementation of above approach:
Count = 500000 Count = 166667
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Exactly n distinct prime factor numbers from a to b
- Least prime factor of numbers till n
- Sum of Maximum and Minimum prime factor of every number in the Array
- Count of subarrays whose products don't have any repeating prime factor
- Count all the numbers in a range with smallest factor as K
- Count minimum factor jumps required to reach the end of an Array
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Prime Factor
- Minimum and Maximum prime numbers in an array
- Find count of Almost Prime numbers from 1 to N
- Sum of all the prime numbers with the count of digits ≤ D
- Count of subarrays having exactly K prime numbers
- Count of numbers below N whose sum of prime divisors is K
- N-th prime factor of a given number
- k-th prime factor of a given number
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.