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:
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Print the nearest prime number formed by adding prime numbers to N
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Quick ways to check for Prime and find next Prime in Java
- Find coordinates of a prime number in a Prime Spiral
- Check if a prime number can be expressed as sum of two Prime Numbers
- Print prime numbers with prime sum of digits in an array
- Check whether the sum of prime elements of the array is prime or not
- Sum of prime numbers without odd prime digits
- Sum of each element raised to (prime-1) % prime
- 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
- Count Balanced Binary Trees of Height h
- Print the balanced bracket expression using given brackets
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.