簡単 0件解決済み 正答率0%

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.

制約

0 ≤ n ≤ 10¹⁸

例

例 1
入力:
n = 153

期待される出力:
expected = True
入力:
long long n = 153;

期待される出力:
bool expected = true;
入力:
long n = 153;

期待される出力:
bool expected = true;

解説

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

例 2
入力:
n = 10

期待される出力:
expected = False
入力:
long long n = 10;

期待される出力:
bool expected = false;
入力:
long n = 10;

期待される出力:
bool expected = false;

解説

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

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。