题目描述
一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如,6的因子为1、2、3,而6=1+2+3,因此6是"完数"。编程序找出N之内的所有完数,并按下面格式输出其因子:
输入
N
输出
? its fastors are ? ? ?
样例输入
1000样例输出
6 its fastors are 1 2 3 28 its fastors are 1 2 4 7 14 496 its fastors are 1 2 4 8 16 31 62 124 248#include<stdio.h> int main() { int n; scanf("%d", &n); int i,j; int count = 0; for (i = 2; i <= n; i++) { count = 0; for (j = 1; j <= i / 2; j++) { if (i % j == 0) { count+=j; } } if (count == i) { printf("%d its fastors are", i); for (j = 1; j <= i / 2; j++) { if (i % j == 0) { if (j == i / 2) { printf(" %d\n", j); } else { printf(" %d", j); } } } } } return 0; }
SWUST OJ44完数
最新推荐文章于 2024-07-19 23:15:41 发布