Perfect primes P90664


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 1n40000001\leq n \leq 4000000. 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
    0
    

    Output

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