Perfect primes

Given a natural number n, let s(n) be the sum of the digits (in base 10)
of n. We say that n is a perfect prime if the infinite sequence formed
by n, s(n), s(s(n)), … only contains prime numbers. For instance, 977 is
a perfect prime, because 977, as well as 9 + 7 + 7 = 23, 2 + 3 = 5, 5,
5, … are prime numbers.

Input

Each line of the input contains a number 1 ≤ n ≤ 16 ⋅ 10⁶. A line with
n = 0 marks the end of the input.

Output

For each n, print in a line “yes” or “no”, depending on whether n is a
perfect prime or it is not.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:15:31.147Z

© Jutge.org, 2006–2026.
https://jutge.org
