A positive integer with digits a, b, c, d… is called an Armstrong number of order n if following condition is satisfied.
abcd... = an + bn + cn + dn +...
153 = 1*1*1 + 5*5*5 + 3*3*3 = 1 + 125 + 27 = 153 Therefore, 153 is an Armstrong number.
Input : 100 400 Output :153 370 371 Explanation : 100 and 400 are given two integers.(interval) 153 = 1*1*1 + 5*5*5 + 3*3*3 = 1 + 125 + 27 = 153 370 = 3*3*3 + 7*7*7 + 0 = 27 + 343 = 370 371 = 3*3*3 + 7*7*7 + 1*1*1 = 27 + 343 +1 = 371
The approach implemented below is simple. We traverse through all numbers in given range. For every number, we first count number of digits in it. Let the number of digits in current number be n. Them we find sum of n-th power of all digits. If sum is equal to i, we print the number.
153 370 371
This article is contributed by Aditya Ranjan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Program for Armstrong Numbers
- Print all integers that are sum of powers of two given numbers
- K-th smallest element after removing given integers from natural numbers | Set 2
- Median in a stream of integers (running integers)
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Find the prime P using given four integers
- Number of solutions for x < y, where a <= x <= b and c <= y <= d and x, y are integers
- Factorial of an Array of integers
- How to sum two integers without using arithmetic operators in C/C++?
- Sum of last digit of all integers from 1 to N divisible by M
- Sum of f(a[i], a[j]) over all pairs in an array of n integers
- Maximum GCD of N integers with given product
- Number of N digit integers with weight W
- Find the number of integers from 1 to n which contains digits 0's and 1's only
- Most frequent factor in a range of integers
Improved By : Mithun Kumar