In number theory, a Balanced Prime is a prime number with equal-sized prime gaps above and below it, so that it is equal to the arithmetic mean of the nearest primes above and below. Or to put it algebraically, given a prime number pn, where n is its index in the ordered set of prime numbers,
First few balanced prime are 5, 53, 157, 173……
Given a positive integer N. The task is to print Nth balanced prime number.
Input : n = 2 Output : 53 Input : n = 3 Output : 157
The idea is to generate prime numbers using Sieve of Eratosthenes and store it in an array. Now iterate over the array to check whether it is balanced prime or not and keep counting the balanced prime. Once you reach the nth prime, return it.
Below is the implementation of this approach:
- Print the nearest prime number formed by adding prime numbers to N
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Quick ways to check for Prime and find next Prime in Java
- Print prime numbers with prime sum of digits in an array
- Check if a prime number can be expressed as sum of two Prime Numbers
- Find coordinates of a prime number in a Prime Spiral
- Check whether the sum of prime elements of the array is prime or not
- Sum of each element raised to (prime-1) % prime
- Sum of prime numbers without odd prime digits
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Number of balanced parenthesis substrings
- Print all combinations of balanced parentheses
- Print the balanced bracket expression using given brackets
- Count Balanced Binary Trees of Height h
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
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.