计算机17-3,4作业E

E.complete number

Description

完数是指一个整数的因子和等于这个数本身,例如6=1+2+3,所以6是一个完数。

按照给定数据范围,找出期中所有完数并输出。

Input

数据范围N,即指在1~N之间寻找完数

Output

完数序列

Sample Input
100
Sample Output

6

28

 1 import java.util.*;
 2 public class Main{
 3     public static void main(String[] args){
 4         Scanner in = new Scanner(System.in);
 5         int num = in.nextInt();
 6         for(int i=6;i<=num;i++){
 7             int sum = 0;
 8             for(int j=1;j<i;j++)
 9                 if(i%j==0){
10                     sum += j;
11                 }
12             if(sum==i)
13                 System.out.println(i);
14         }
15     }
16 }

猜你喜欢

转载自www.cnblogs.com/1Kasshole/p/9007335.html
今日推荐