public class PerfectNumber {
public static void main(String[] args) {
int i, j, sum; /* i表示要判断的数,j表示因子,sum表示因子之和*/
for (i = 2; i <= 1000; i++){
sum = 1;
for (j = 2; j <= i / 2; j++)
if (i%j == 0)
sum += j;
if (sum == i){
System.out.print("完数"+i+"因子为1 ");
for (j = 2; j <= i/2; j++)
if (i%j == 0)
System.out.print(" "+j);
System.out.println();
}
}
}
}
完数的实现
最新推荐文章于 2021-08-18 23:16:31 发布