Armstrong Number - Problem
An Armstrong number (also known as a narcissistic number or pluperfect digital invariant) is a fascinating mathematical curiosity that equals the sum of its own digits each raised to the power of the number of digits.
More formally: A k-digit number n is an Armstrong number if and only if the k-th power of each digit sums to n.
Examples:
153is a 3-digit Armstrong number: 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ✓9474is a 4-digit Armstrong number: 9⁴ + 4⁴ + 7⁴ + 4⁴ = 6561 + 256 + 2401 + 256 = 9474 ✓123is NOT an Armstrong number: 1³ + 2³ + 3³ = 1 + 8 + 27 = 36 ≠ 123 ✗
Given an integer n, return true if it's an Armstrong number, false otherwise.
Input & Output
example_1.py — Simple 3-digit Armstrong
$
Input:
153
›
Output:
true
💡 Note:
153 is a 3-digit number. 1³ + 5³ + 3³ = 1 + 125 + 27 = 153, which equals the original number.
example_2.py — Single digit (always Armstrong)
$
Input:
5
›
Output:
true
💡 Note:
5 is a 1-digit number. 5¹ = 5, which equals the original number. All single digits are Armstrong numbers.
example_3.py — Not an Armstrong number
$
Input:
123
›
Output:
false
💡 Note:
123 is a 3-digit number. 1³ + 2³ + 3³ = 1 + 8 + 27 = 36 ≠ 123, so it's not an Armstrong number.
Constraints
- 0 ≤ n ≤ 108
- The input will always be a non-negative integer
- Note: All single-digit numbers (0-9) are Armstrong numbers
Visualization
Tap to expand
Understanding the Visualization
1
Count the Evidence
Count how many digits the suspect number has - this becomes our power
2
Extract Each Clue
Extract each digit one by one using mathematical operations
3
Calculate Powers
Raise each digit to the power equal to the total digit count
4
Sum the Evidence
Add up all the calculated powers
5
Make the Verdict
Compare the sum with the original number - if equal, it's an Armstrong number!
Key Takeaway
🎯 Key Insight: Armstrong numbers are mathematical gems where the sum of digits raised to the power of digit count equals the original number. Use modulo arithmetic for efficient digit extraction!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code