题解 | #完数#一样的
完数
https://www.nowcoder.com/practice/3d8cabccd6224b638573293a811c6346
#include <iostream> #include <vector> using namespace std; //判断完数 int Sum(int k) { int sum = 0; for (int i = 1; i < k; i++) { if (k % i == 0) { sum += i; } } return sum; } int main() { vector<int> eiVector; //完数 int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { if (i == Sum(i)) { eiVector.push_back(i); } } for (int i = 0; i < eiVector.size(); i++) { printf("%d ", eiVector[i]); } }