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 firstname.lastname@example.org. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- XOR and OR of all N-digit Armstrong numbers
- Program for Armstrong Numbers
- Sum of all armstrong numbers lying in the range [L, R] for Q queries
- 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
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Permutation of first N positive integers such that prime numbers are at prime indices
- Median in a stream of integers (running integers)
- Array Range Queries to find the Maximum Armstrong number with updates
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Find N distinct integers with zero sum
- Find N distinct integers with sum N
- Find the prime P using given four integers
- Sum of f(a[i], a[j]) over all pairs in an array of n integers
- Check if the XOR of an array of integers is Even or Odd
- Find K consecutive integers such that their sum is N
- Largest Coprime Set Between two integers
- Sum of last digit of all integers from 1 to N divisible by M
- Factorial of an Array of integers
- Maximum GCD of N integers with given product
Improved By : Mithun Kumar