Tous les défis
Facile 0 résolus 0 % de réussite

Armstrong Number

Check whether a number equals the sum of its digits raised to the digit count.

A number with k digits is an Armstrong number if the sum of each digit raised to the power k equals the number. For example 153 = 1³ + 5³ + 3³.

Implement is_armstrong(n).

Input

n: A non-negative integer.

Output

Return true if n is an Armstrong number.

Contraintes

0 ≤ n ≤ 10¹⁸

Exemples

Exemple 1
Entrée :
n = 153

Sortie attendue :
expected = True
Entrée :
long long n = 153;

Sortie attendue :
bool expected = true;
Entrée :
long n = 153;

Sortie attendue :
bool expected = true;

Explication

1³ + 5³ + 3³ = 1 + 125 + 27 = 153.

Exemple 2
Entrée :
n = 10

Sortie attendue :
expected = False
Entrée :
long long n = 10;

Sortie attendue :
bool expected = false;
Entrée :
long n = 10;

Sortie attendue :
bool expected = false;

Explication

1² + 0² = 1, which is not 10.

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.