Perfect primes (2) P16356


Statement
 

pdf   zip

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.

Public test cases
  • Input

    977
    1
    7
    17
    15999923
    16000000
    0
    

    Output

    yes
    no
    yes
    no
    yes
    no
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++