题解 | #完数VS盈数#
完数VS盈数
https://www.nowcoder.com/practice/ccc3d1e78014486fb7eed3c50e05c99d
#include <cstdio> #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> vece; vector<int> vecg; for (int i = 2; i <= 60; i++) { if (i == sum(i)) { vece.push_back(i); } else if (i < sum(i)) { vecg.push_back(i); } } printf("E:"); for (int i = 0; i < vece.size(); i++) { printf(" %d", vece[i]); } printf("\n"); printf("G:"); for (int i = 0; i < vecg.size(); i++) { printf(" %d", vecg[i]); } printf("\n"); }