题解 | #完数与盈数#
完数与盈数
http://www.nowcoder.com/practice/df0d850e41894d06a165bf445ec8a8b4
#include<iostream>
#include<set>
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
set<int> Set, a, b;
int total,num,i;
for (num = 2; num <= 60; ++num) {
total = 0;
for (i = 1; i * i <= num; ++i) {
if (num % i == 0) {
Set.insert(i);
if(num / i != num)
Set.insert(num / i);
}
}
for (auto it : Set)
total = total + it;
if (total == num)
a.insert(num);
else if (total > num)
b.insert(num);
Set.clear();
}
if (a.size()) {
cout << "E:";
for (auto it : a)
cout << " " << it;
}
if (b.size()) {
cout << " G:";
for (auto it : b)
cout << " " << it;
}
}