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
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
- Print prime numbers with prime sum of digits in an array
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Find all Autobiographical Numbers with given number of digits
- Find a sequence of N prime numbers whose sum is a composite number
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Sum of prime numbers without odd prime digits
- Sum of all the prime numbers with the count of digits ≤ D
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Print the nearest prime number formed by adding prime numbers to N
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Check if a prime number can be expressed as sum of two Prime Numbers
- Largest number with prime digits
- Recursive sum of digits of a number is prime or not
- Count of Prime digits in a 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.