Given an integer D, the task is to find the sum of all the prime numbers whose count of digits is less than or equal to D.
Input: D = 2
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89 and 97 are
the prime numbers having digits less than or equal
to 2 and the sum of these prime numbers is 1060.
Input: D = 3
Approach: Generate all prime numbers using Sieve of Eratosthenes upto maximum D-digit number then find the sum of all the prime numbers in the same range.
Below is the implementation of the above approach:
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
- Print prime numbers with prime sum of digits in an array
- Sum of prime numbers without odd prime digits
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Count numbers in a given range whose count of prime factors is a Prime Number
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Count numbers in range [L, R] whose sum of digits is a Prime Number
- 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
- Find all the prime numbers of given number of digits
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Prime numbers after prime P with sum S
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if sum of count of digits of array elements is Prime or not
- Sum of all prime divisors of all the numbers in range L-R
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array
- Find all numbers between range L to R such that sum of digit and sum of square of digit is prime
- Print the nearest prime number formed by adding prime numbers to N
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
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.