Given a number N. The task is to print the nearest prime if the number is not prime by making it prime by adding prime numbers sequentially from 2.
Input: N = 8
8 is not prime, so add the first prime to it to get 10
10 is not prime, hence add the second prime i.e., 3 to get 13 which is prime.
Input: N = 45
Approach Using Sieve of Eratosthenes, mark the prime index by 1 in isprime list and store all the prime numbers in a list prime. Keep adding prime numbers sequentially to N, till it becomes prime.
Below is the implementation of the above approach:
- Print prime numbers with prime sum of digits in an array
- Nearest prime less than given number n
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Count of distinct sums that can be obtained by adding prime numbers from given arrays
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Permutation of first N positive integers such that prime numbers are at prime indices
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- 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
- Print prime numbers in a given range using C++ STL
- Program to print first N Prime numbers
- Print all prime numbers less than or equal to N
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime