Narcissistic numbers P29054


Statement
 

pdf   zip

thehtml

In this exercice, we say that a natural number n with k digits is narcissistic, when n is equal to the sum of the k-th power of its digits. For example, 153 and 1634 are narcissistic numbers, as 153 = 13+53+33 and 1634 = 14 + 64 + 34 + 54.

A sequence of natural numbers is insufferably narcissistic when all the elements in the sequence are narcissistic numbers.

Write a program which, given a non-empty sequence of natural numbers, indicates whether it is insufferably narcissitic or not.

Your program must include, implement and use a function

bool is_narcissistic (int n);

indicating whether a natural n is narcissistic or not.

Input

The input is formed by a non-empty sequence of natural numbers.

Output

The program has to indicate whether the sequence is insufferably narcissitic.

Follow the format described in the examples. Your code should follow the style rules and include the appropriate comments.

Public test cases
  • Input

    0 1 2 3 4 5 6 7 8 9
    

    Output

    SI
    
  • Input

    73 153 173 351 370 371 407 704
    

    Output

    NO
    
  • Input

    153 370 1634 8208 407 9474 92727 93084 6
    

    Output

    SI
    
  • Input

    1634 4361 4749 8208 9474 8028
    

    Output

    NO
    
  • Information
    Author
    Professorat de PRO1
    Language
    English
    Translator
    Maria Serna
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++ Python