Given an integer D, the task is to find all the prime numbers having D digits.
Input: D = 1
Output: 2 3 5 7
Input: D = 2
Output: 11 13 17 19 23 29 31 37 41 43 47 53 61 67 71 73 79 83 89 97
Approach: Numbers with D digits lie in the range [10(D – 1), 10D – 1]. So, check all the numbers in this interval and to check the number is prime or not, use Sieve of Eratosthenes to generate all the primes.
Below is the implementation of the above approach:
2 3 5 7
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.
- Count all prime numbers in a given range whose sum of digits is also prime
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Print prime numbers with prime sum of digits in an array
- Sum of prime numbers without odd prime digits
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Find smallest number with given number of digits and sum of digits under given constraints
- Find the Largest number with given number of digits and sum of digits
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Sum of all the prime numbers with the count of digits ≤ D
- Find the average of k digits from the beginning and l digits from the end of the given number
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Find all Autobiographical Numbers with given number of digits
- Number of digits in the nth number made of given four digits
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
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.