EasyFoundational
Check Whether a Number Is an Armstrong Number
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- Mathematics and Number Theory
Description
Given a non-negative integer n, determine whether it is an Armstrong number.
An Armstrong number is a number equal to the sum of its digits, where each digit is raised to the power of the total number of digits in the number. Use the standard decimal representation; 0 has one digit.
For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. The number 120 is not, because 1^3 + 2^3 + 0^3 = 9.
Return true if n is an Armstrong number; otherwise return false.
Implement isArmstrong(n).
Constraints
0 <= n <= 1000000000
Sample cases
3Sample 1
Input
n = 153
Expected output
true
Sample 2
Input
n = 120
Expected output
false
Sample 3
Skills and languages
Concepts
- Control Flow and Data Types
- Number Bases and Digit Manipulation
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer