int isPerfect(int n) { int isPerfect = 0; int sum = 0; if (n > 1) { for (int i = 1; i < n / 2 + 1; i++) { if (n % i == 0) { sum += i; } } if (n == sum) { isPerfect = 1; } } return isPerfect; }
int main() { int n, m; scanf("%d %d", &n, &m); int cnt = 0; for (int i = n; i <= m; i++) { if (isPerfect(i)) { if (cnt > 0) { printf(" "); } printf("%d", i); cnt ++; } } if (cnt == 0) { printf("NIL\n"); } return 0; }