![]() |
VOOZH | about |
Given a positive integer N, the task is to check if N is a strong prime or not.
In number theory, a strong prime is a prime number that is greater than the arithmetic mean of nearest prime numbers i.e next and previous prime numbers.
First few strong prime numbers are 11, 17, 29, 37, 41, 59, 67, 71, ...
A strong prime Pn can be represented as-
where n is its index in the ordered set of prime numbers.
Examples:
Input: N = 11
Output: Yes
11 is 5th prime number, the arithmetic mean of 4th and 6th prime number i.e. 7 and 13 is 10.
11 is greater than 10 so 11 is a strong prime.Input: N = 13
Output: No
13 is 6th prime number, the arithmetic mean of 5th (11) and 7th (17) is (11 + 17) / 2 = 14.
13 is smaller than 14 so 13 is not a strong prime.
Approach:
Below is the implementation of the above approach:
Yes
Time Complexity: O(n1/2)
Auxiliary Space: O(1), since no extra space has been taken.