Dcoder icon

The Armstrong Number @ Dcoder

By Lochard | As a newbie programmer | 18 May 2023


Problem: An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.

For example, consider the number 371. The sum of the cube of its digits is 3^3 + 7^3 + 1^3 = 27 + 343 + 1 = 371. Therefore, 371 is an Armstrong Number. Given a 3 digit integer, determine whether the number is Armstrong Number or not. If it is, print "YES" else print "NO", without the quotes.

Input: A 3-digit integer N.

Output: "YES" or "NO", without the quotes

Constraints: 100 ≤ N ≤ 999

Sample Input: 371

Sample Output: 

YES

n = int(input())
print('YES' if int((n//100)**3 + (n//10%10)**3 + (n%10)**3) == n else 'NO') 

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.