题解 | #完数VS盈数#

完数VS盈数

https://www.nowcoder.com/practice/ccc3d1e78014486fb7eed3c50e05c99d

#include<cstdio>
#include<vector>

int sumYingzi(int n) {
    int sum = 0;
    for (int j = 1 ; j < n ; ++j) {
        if (n % j == 0) {
            sum = sum + j;
        }
    }
    return sum;
}
using namespace std;
int main() {
    vector<int> wanshu;
    vector<int> yingshu;
    for (int i = 2 ; i < 61 ; ++i) {
        if (i == sumYingzi(i)) {
            wanshu.push_back(i);
        } else if (i < sumYingzi(i)) {
            yingshu.push_back(i);
        }
    }
    printf("E:");
    for (unsigned i = 0 ; i < wanshu.size(); ++ i) {
        printf(" %d", wanshu[i]);
    }
    printf("\n");
    printf("G:");
    for (unsigned i = 0 ; i < yingshu.size(); ++ i) {
        printf(" %d", yingshu[i]);
    }
    printf("\n");
}

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务