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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of largest prime factor of each number less than equal to n
- Count of subarrays whose products don't have any repeating prime factor
- Find largest factor of N such that N/F is less than K
- Largest number less than N whose each digit is prime number
- Count all prime numbers in a given range whose sum of digits is also prime
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Numbers less than N which are product of exactly two distinct prime numbers
- Print all Semi-Prime Numbers less than or equal to N
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Sum of Semi-Prime Numbers less than or equal to N
- Print all Prime Quadruplet of a number less than it
- Count pairs with sum as a prime number and less than n
- Sum of Maximum and Minimum prime factor of every number in the Array
- Exactly n distinct prime factor numbers from a to b
- Least prime factor of numbers till n
- Count of distinct power of prime factor of N
- Count all the numbers in a range with smallest factor as K
- Sum of elements in an array whose difference with the mean of another array is less than k
- Minimum number of sets with numbers less than Y
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.