DSTJZ


私信TA

用户名:dotcpp0721777

访问量:7161

签 名:

天下难事,必作于易;天下大事,必作于细。

等  级
排  名 49
经  验 11705
参赛次数 13
文章发表 324
年  龄 18
在职情况 学生
学  校 狗熊岭23届毕业生
专  业

  自我简介:

TA的其他文章


参考代码:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		// divisor用来记录每个因子
		int[] divisor = new int[1000];
		for(int i = 6; i <= n; i++) {
			int sum = 0;// 总和
			int cnt = 0;// 因子的数量
			// 枚举因子
			for(int j = 1; j < i; j++) {
				if(i % j == 0) {
					sum += j;
					divisor[cnt++] = j;
				}
			}
			if(sum == i) {
				System.out.print(i + " its factors are ");
				for(int j = 0; j < cnt; j++) {
					System.out.print(divisor[j] + " ");
				}
				System.out.println();
			}
		}
	}
}


 

0.0分

0 人评分

  评论区

  • «
  • »