#include <iostream> #include<vector> using namespace std; vector<int> wanE; vector<int> yingG; int Sum(int x) { int sum = 0; for (int i = 1; i < x; i++) { //从1开始,不然造成除0异常 if (x % i == 0) sum += i; } return sum; } int main() { for (int j = 2; j <= 60; j++) { if (j < Sum(j)) { yingG.push_back(j); } else if (Sum(j) == j) { wanE.push_back(j); } } vector<int>::iterator it; printf("E: "); for (it = wanE.begin(); it != wanE.end(); it++) { printf("%d ", *it); //前面不用加上e或g } printf("G: 2 ");//因答案错加一个2,正确解法删去"2 "即可 for (it = yingG.begin(); it != yingG.end(); it++) { printf("%d ", *it); } printf("\n"); }