Given an integer D, the task is to find the sum of all the prime numbers whose maximum position of set bits (farthest set bit from the right) is less than or equal to D.
Note: 2 in binary is 10 and the maximum set bit position is 2. 7 in binary is 111, maximum set bit position is 3.
Input: D = 3
2, 3, 5 and 7 are the only primes
which satisfy the given condition.
Input: D = 8
Approach: The maximum number which satisfies the given condition is 2D – 1. So, generate all prime numbers using Sieve of Eratosthenes upto 2D – 1 then find the sum of all the prime numbers in the same range.
Below is the implementation of the above approach:
- Maximum no. of contiguous Prime Numbers in an array
- Minimum and Maximum prime numbers in an array
- Queries for maximum difference between prime numbers in given ranges
- Minimum and Maximum Prime Numbers of a Singly Linked List
- 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
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Represent a number as a sum of maximum possible number of Prime Numbers
- 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
- Print prime numbers with prime sum of digits in an array
- Check if a prime number can be expressed as sum of two Prime Numbers
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Sum of prime numbers without odd prime digits
- Position of n among the numbers made of 2, 3, 5 & 7
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.