-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperfectNum.cpp
More file actions
43 lines (38 loc) · 903 Bytes
/
Copy pathperfectNum.cpp
File metadata and controls
43 lines (38 loc) · 903 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
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
// first perfect numbers: 6, 28,496,8128,33550336
int PerfectNum = 33550336 + 1;
vector<int> Divisors;
for (int i = 1; i != PerfectNum; i++)
{
if (PerfectNum % i == 0 && PerfectNum / i != 1)
{
Divisors.push_back(i);
}
}
int sum = 0;
for (const auto &element : Divisors)
{
sum += element;
}
if (PerfectNum == sum)
{
cout << "Uhra!!! this is perfect number: " << PerfectNum << endl;
}
else
{
cout << "I am really sorry it is NOT perfect number((" << endl;
}
cout << "Sum is: " << sum << endl;
// to see guts of vector
cout << "Guts of vector: ";
for (const auto &element : Divisors)
{
cout << element << ' ';
}
return 0;
}