Given two numbers A and B. The task is to find the smallest positive integer greater than or equal to 1 such that the sum of all three numbers become a prime number.
Input: A = 2, B = 3
The third number is 2 because if we add all three number the
sum obtained is 7 which is a prime number.
Input: A = 5, B = 3
- First of all store the sum of given 2 number in sum variable.
- Now, check if bitwise and (&) of sum and 1 is equal to 1 or not (checking if the number is odd or not).
- If it is equal to 1 then assign 2 to variable temp and go to step 4.
- Else check sum value of sum and temp variable whether it is prime number or not. If prime, then print the value of temp variable else add 2 to temp variable untill it is less than a prime value.
Below is the implementation of the above approach:
- Find coordinates of a prime number in a Prime Spiral
- Given a number x , find y such that x*y + 1 is not a prime
- Program to find the next prime number
- Program to find the Nth Prime Number
- Find sum of a number and its maximum prime factor
- Find prime number K in an array such that (A[i] % K) is maximum
- Find all the prime numbers of given number of digits
- Find largest prime factor of a number
- Analysis of Different Methods to find Prime Number in Python
- Find Largest Special Prime which is less than or equal to a given number
- Find a sequence of N prime numbers whose sum is a composite number
- Find the number of primitive roots modulo prime
- Number which has the maximum number of distinct prime factors in the range M to N
- Check if a number is divisible by all prime divisors of another number
- Represent a number as a sum of maximum possible number of Prime 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.