ARMSTRONG NUMBER
Armstrong Numbers: The Magical Numbers of Mathematics
An Armstrong number (or Narcissistic number) is a fascinating concept in mathematics. It’s a number that equals the sum of its digits, each raised to the power of the total number of digits.
For example:
- 153:
- 9474:
The uniqueness of Armstrong numbers lies in their self-referential property, making them both intriguing and rare. These numbers are often used in programming challenges to explore looping and mathematical logic.
Armstrong numbers appear in various digit counts:
- 3-digit examples: 153, 370, 371, 407
- 4-digit examples: 9474, 8208
The concept can extend to any number of digits, offering a playground for discovering larger Armstrong numbers using algorithms. These numbers demonstrate the beauty of simple mathematical rules leading to powerful and elegant patterns!
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
int n=sc.nextInt();
int sum=0,temp=n;
int len=numlen(temp);
while(temp!=0){
sum+=Math.pow(temp%10,len);
temp/=10;
}
System.out.print(n==sum?"yes":"no");
}
}
No comments:
Post a Comment