思路

求出 2 到 60 之间数字的因子之和,然后进行比较,判断出是完数还是盈数,并用两个数组分别去存储。

#include<iostream>
#include<vector>

using namespace std;

int judge(int num){
    int sum = 0;
    for(int i = 1; i < num; i ++){
        if(num % i == 0)
            sum += i;
    }
    if(sum == num) return 1;
    if(sum > num) return 0;
    return -1;
}

int main(){
    vector<int> e, g;
    for(int i = 2; i <= 60; i ++){
        if(judge(i) == 1) e.push_back(i);
        else if(judge(i) == 0) g.push_back(i);
    }
    cout << "E:";
    for(int i : e) cout << " " << i;
    cout << endl;
    cout << "G:";
    for(int i : g) cout << " " << i;
    return 0;
}