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’.
- Count of pairs satisfying the given condition
- Count number of ways to cover a distance | Set 2
- Reduce a number to 1 by performing given operations | Set 2
- Minimum integer that can be obtained by swapping adjacent digits of different parity
- Jaro and Jaro-Winkler similarity
- Number of binary strings such that there is no substring of length ≥ 3
- Partitions possible such that the minimum element divides all the other elements of the partition
- Partition the digits of an integer such that it satisfies a given condition
- Count of possible arrays from prefix-sum and suffix-sum arrays
- Smallest number greater than n that can be represented as a sum of distinct power of k
- Find Kth smallest value for b such that a + b = a | b
- Number of pairs of lines having integer intersection points
- Percentage change in Hemisphere volume if radius is changed
- Program to find the time remaining for the day to complete
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.
Improved By : Shashank12