Happy prime

According to the Tenth Doctor, a happy prime was any number which was both happy and prime. He went on to describe a happy number: "Any number that reduces to one when you take the sum of the square of its digits and continue iterating it until it yields 1 is a happy number, any number that doesn't, isn't."

- Tenth Doctor

When the S.S. Pentallian hurtled towards the Torajii sun, Riley Vashtee and Martha Jones used the happy prime sequence of 313, 331, 367 and 379 to reach the ship's back-up engines, with help from the Tenth Doctor.

The Doctor bemoaned Riley and Martha's lack of knowledge about happy primes and wondered why there appeared to be falling standards in the education of what he called "recreational mathematics". (TV: 42).

Definition
A happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, such as 7, which has the sequence 7, 49, 97, 130, 10, 1, and therefore 7 is a happy number. Those that do not end in 1 are unhappy numbers (or sad numbers).

A happy prime is a number that is both happy and prime. The happy primes below 500 are: 7, 13, 19, 23, 31, 79, 97, 103, 109, 139, 167, 193, 239, 263, 293, 313, 331, 367, 379, 383, 397, 409, 487.