Given a positive number n, the task is to check whether the given number is Interprime or not. If the given number is Interprime print ‘YES’ Otherwise Print ‘NO’.
Interprime : In Mathematics, An interprime is a positive integer representing average of two consecutive odd prime numbers.
The first few Interprimes are –
4, 6, 9, 12, 15, 18, 21, 26, 30, 34, 39, 42, 45, 50, 56, 60, 64, 69, 72, 76, 81, 86, 93, 99
Input : 12
Output : YES
Explanation: 12 is average of consecutive prime number 11 and 13.
Input : 20
Output : NO
A Simple solution of this problem is to generate prime numbers and check if we can get the the given average from consecutive odd prime number or not.
- Start generating prime number ‘p’ form i=3 to the prime number p > n
- if we find average of p and p+1 as the given number n, then stop and Print ‘YES’
- If we don not find such p and p+1 with the given average print ‘NO’.
An Efficient solution is to check average of prime number p1 and p2 only, such that p1 and p2 are consecutive and p1 < n < p2.
- calculate consecutive prime number p1 and p2. such that p1 < n < p2.
- calculate average of p1 and p2.
- Print ‘YES’ if we get the given average Otherwise print ‘NO’.
- Compare numbers represented by Linked Lists
- Number of ways to reach (X, Y) in a matrix starting from the origin
- Find if a crest is present in the index range [L, R] of the given array
- Find the last two missing digits of the given phone number
- Multiply Large Numbers using Grid Method
- Maximum frequency of a remainder modulo 2i
- Sum of the updated array after performing the given operation
- Remove an element to minimize the LCM of the given array
- Find closest integer with the same weight
- Check whether the given decoded string is divisible by 6
- Find the minimum possible health of the winning player
- Construct an array from its pair-product
- Count of odd and even sum pairs in an array
- Number of ways to divide string in sub-strings such to make them in lexicographically increasing sequence
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.
Improved By : Shashank12