English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

I used brute force method. Perhaps there is more elegant way to do this...... maybe not.
public class Perfect{
public static void main (String[]args){
for(int i=1; i<=500;i++){
int r=0;
for(int c=i/2;c>=1;c--){
if(i%c==0){
r+=c;
if(r==i&& c==1){
System.out.println(i+" is a perfect number");
}
}
}
}
}
}

2007-08-25 22:44:26 · answer #1 · answered by Sheqi Nonda 3 · 0 0

currently there are only 44 perfect numbers known , just program them hardcoded into an array. and look them up.

2007-08-25 19:21:54 · answer #2 · answered by gjmb1960 7 · 0 0

fedest.com, questions and answers