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 SS 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: 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193, 203, 208, 219, 226, 230, 236, 239, 262, 263, 280, 291, 293, 301, 302, 310, 313, 319, 320, 326, 329, 331, 338, 356, 362, 365, 367, 368, 376, 379, 383, 386, 391, 392, 397, 404, 409, 440, 446, 464, 469, 478, 487, 490, and 496.