题解 | #完数与盈数#
完数与盈数
http://www.nowcoder.com/practice/df0d850e41894d06a165bf445ec8a8b4
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
vector<int>numberE;
vector<int>numberG;
int sum(int x){ //求因子和
int sum=0;
for(int i=1;i<x;++i){
if(x%i==0){
sum+=i;
}
}
return sum;
}
int main(){
for(int i=2;i<=60;++i){
if(i==sum(i)){ //是完数则添加
numberE.push_back(i);
}
else if(i<sum(i)){ //是盈数则添加
numberG.push_back(i);
}
}
printf("E:"); //打印输出
for(int i=0;i<numberE.size();++i){
printf(" %d",numberE[i]);
}
printf(" G:");
for(int i=0;i<numberG.size();++i){
printf(" %d",numberG[i]);
}
printf("\n");
return 0;
}