题解 | #完数VS盈数#
完数VS盈数
https://www.nowcoder.com/practice/ccc3d1e78014486fb7eed3c50e05c99d
#include <stdio.h> int main() { int perfect[60] = {0}; // 记录完数 int abundant[60] = {0}; // 记录盈数 int sum; for (int i = 2; i <= 60; i++) { sum = 0; for (int j = 1; j <= i / 2; j++) { if (i % j == 0) { sum += j; } } if (sum == i) { perfect[i] = i; } else if (sum > i) { abundant[i] = i; } } printf("E:"); for (int i = 2; i <= 60; i++) { if (perfect[i] != 0) { printf(" %d", perfect[i]); } } printf("\nG:"); for (int i = 2; i <= 60; i++) { if (abundant[i] != 0) { printf(" %d", abundant[i]); } } return 0; }