Editor

Armstrong Number

#210 · Math · Beginner · 30 XP · about 5 min

Take a number with k digits, raise each digit to the power k and add the results. If you get the number back, it is an Armstrong number. 153 has 3 digits, and 13 + 53 + 3**3 = 1 + 125 + 27 = 153.

Write is_armstrong(n) that returns True if the non-negative integer n is an Armstrong number and False otherwise.

Examples

is_armstrong(153)     # returns True
is_armstrong(9474)    # returns True     (9**4 + 4**4 + 7**4 + 4**4)
is_armstrong(10)      # returns False    (1**2 + 0**2 = 1)

Constraints

  • 0 <= n <= 10^12

Note

Every one-digit number is an Armstrong number, 0 included, because a digit to the power 1 is itself.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.