Perfect primes

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

Input

Each line of the input contains a number 1n161061 \le n \le 16 \cdot 10^6. A line with n=0n=0 marks the end of the input.

Output

For each nn, print in a line “yes” or “no”, depending on whether nn 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