题解 | #完数与盈数#
完数与盈数
https://www.nowcoder.com/practice/df0d850e41894d06a165bf445ec8a8b4
#include<cstdio> #include<string> #include<vector> using namespace std; int sum(int i){ int sum=0; for (int j = 1; j < i; ++j) { if (i%j==0){ sum=sum+j; } } return sum; } int main(){ vector<int> Evec; vector<int> Gvec; for (int i = 2; i <=60 ; ++i) { if (i== sum(i)){ Evec.push_back(i); } else if (i< sum(i)){ Gvec.push_back(i); } } printf("E:"); for (int i = 0; i < Evec.size(); ++i) { printf(" %d",Evec[i]); } printf("\n"); printf("G:"); for (int i = 0; i < Gvec.size(); ++i) { printf(" %d",Gvec[i]); } printf("\n"); }