题解 | #完全数计算#
完全数计算
https://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
#include <stdio.h> #include <string.h> int main() { int n; scanf("%d", &n); int k = 1; int sun = 0; int num = 0; while (k <= n) { for (int i = 1; i < k; i++) { if (k % i == 0) sun += i; } if (sun == k) { num++; } sun = 0; k++; } printf("%d", num); return 0; }