题解 | #完数#
完数
https://www.nowcoder.com/practice/3d8cabccd6224b638573293a811c6346
#include<cstdio> #include<iostream> #include<vector> using namespace std; int sum(int m) { int sum=0; for(int i=1;i<=m/2;i++) { if(m%i==0) { sum=sum+i; } } return sum; } int main() { int n; int i; int count; vector<int> wanshu; vector<int> yingshu; vector<int> shu; scanf("%d",&n); for(i=1;i<n;i++){ count=sum(i); if(count==i) { wanshu.push_back(i); } else { shu.push_back(i); } } for(auto x:wanshu) { printf("%d ",x); } }