import java.io.*; import java.util.ArrayList; public class Main { public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); public static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); public static PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out)); static void PerfectNumber(int n) { ArrayList<Integer> yinshu = new ArrayList(); // 因子保存在一个 ArrayList 里。(普通的数组长度是固定的) int sum = 0; for (int i = 1; i <= n / 2; i++) { // 判断因子的方法:从 1 一直循环到 n / 2,如果可以整除就是因子 if (n / i == (double) n / (double) i) { yinshu.add(i); } } for (int i : yinshu) { sum += i; } if (sum == n) { cout.printf("%d its factors are ", n); for (int i = 0; i < yinshu.size(); i++) { if (i == yinshu.size() - 1) { cout.printf("%d\n", yinshu.get(i)); } else { cout.printf("%d ", yinshu.get(i)); } } } } public static void main(String[] args) throws Exception { cin.nextToken(); int n = (int) cin.nval; for (int i = 1; i <= n; i++) { PerfectNumber(i); } cout.flush(); } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:400 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:633 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:485 |
C语言训练-大、小写问题 (C语言代码)浏览:649 |
WU-输入输出格式练习 (C++代码)浏览:1133 |
printf基础练习2 (C语言代码)浏览:690 |
Hello, world! (C语言代码)浏览:766 |
川哥的吩咐 (C语言代码)浏览:663 |
C语言程序设计教程(第三版)课后习题12.5 (C语言代码)浏览:799 |
C语言训练-8除不尽的数 (C语言代码)浏览:1469 |