-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompletionVS.Surplus.cpp
More file actions
51 lines (51 loc) · 989 Bytes
/
CompletionVS.Surplus.cpp
File metadata and controls
51 lines (51 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
// vector 可用于邻接表,尤其擅长处理数据量不确定的情况
vector<int> numE;
vector<int> numG;
int judge(int x)
{
int sum = 0;
for (int i = 1; i < x; i++)
{
if (x % i == 0)
{
sum += i;
}
}
if (sum == x)
{ // 完数
numE.push_back(x);
}
else if (sum > x)
{ // 盈数
numG.push_back(x);
}
return 0;
}
int main(int argc, char const *argv[])
{
for (int i = 2; i <= 60; i++)
{
judge(i);
}
cout << "E:";
for (int k = 0; k < numE.size(); k++)
{
if (k == numE.size() - 1)
{
cout << numE[k];
}
cout << " " << numE[k];
}
cout << endl;
cout << "G:";
for (int k = 0; k < numG.size(); k++)
{
cout << " " << numG[k];
}
cout << endl;
return 0;
}