Problem 60957. List balanced primes
A balanced prime of order k is one that equals the average of the k primes before it and the k primes after it. For example, 79 is the first balanced prime of order 2; it is the average of 71, 73, 83, and 89.
Cody Problem 47798 asks us to determine whether a number is a balanced prime of order one. For order one, balanced primes are equal to mean-of-2 primes.
Write a function that returns the nth prime number that is the average of the k primes before it and the k primes after it.
Solution Stats
Problem Comments
-
2 Comments
Matthew
on 9 Jul 2025
I like the problem, but the test suite is unnecessarily exhaustive IMO. Spent more time trying to get my code to run faster just so it didn't time out.
ChrisR
on 12 Jul 2025
Thanks for the comment, Matthew. My initial solution for this problem ran much more slowly, and I found a way to speed it up significantly. If I get good enough at coding, I might be able to tackle some of Ramon Villamangca's "easy sequences" problems!
Solution Comments
Show commentsProblem Recent Solvers5
Suggested Problems
-
5 Solvers
More from this Author310
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!