Given a number N. The task is to count the number of prime numbers from 2 to N that can be expressed as a sum of two consecutive primes and 1.
Input: N = 27
13 = 5 + 7 + 1 and 19 = 7 + 11 + 1 are the required prime numbers.
Input: N = 34
13 = 5 + 7 + 1, 19 = 7 + 11 + 1 and 31 = 13 + 17 + 1.
Approach: An efficient approach is to find all the primes numbers up to N using Sieve of Eratosthenes and place all the prime numbers in a vector. Now, run a simple loop and add two consecutive primes and 1 then check if this sum is also a prime. If it is then increment the count.
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 of primes below N which can be expressed as the sum of two primes
- Check if an integer can be expressed as a sum of two semi-primes
- Count of primes in a given range that can be expressed as sum of perfect squares
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Check if a number can be expressed as a sum of consecutive numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if a number can be expressed as sum two abundant numbers
- Check if a number can be expressed as sum of two Perfect powers
- Check if a given number can be expressed as pair-sum of sum of first X natural numbers
- Number expressed as sum of five consecutive integers
- Find the prime numbers which can written as sum of most consecutive primes
- Numbers within a range that can be expressed as power of two numbers
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Count array elements that can be represented as sum of at least two consecutive array elements
- Check if a number can be expressed as x^y (x raised to power y)
- Check whether a number can be expressed as a product of single digit numbers
- Check if a number can be expressed as power | Set 2 (Using Log)
- Check if a number can be expressed as a^b | Set 2
- Check if a number can be expressed as 2^x + 2^y
- Check if N can be expressed as product of 3 distinct 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.