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:
- Check if an integer can be expressed as a sum of two semi-primes
- Length of largest sub-array having primes strictly greater than non-primes
- Find the prime numbers which can written as sum of most consecutive primes
- Count Primes in Ranges
- Count number of primes in an array
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count numbers which can be represented as sum of same parity primes
- Circular primes less than n
- Palindromic Primes
- Print all multiplicative primes <= N
- Print all safe primes below N
- Print all Proth primes up to N
- Product of all primes in the range from L to R
- Alternate Primes till N
- Check if a number is sandwiched between primes