-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem23.cpp
executable file
·65 lines (55 loc) · 970 Bytes
/
Problem23.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
// Sums the Divisors of a number
int getSumOfDivs(int num)
{
int i = 2;
double sqt = sqrt (num);
int sum = 1;
while ( i < sqt )
{
if (num % i == 0)
{
sum += i + num/i;
//cout << i << endl;
}
i++;
}
return sum;
}
// Checks whether a number is Abundant
bool isAbundantNum(int num)
{
if (getSumOfDivs(num) > num)
{
return true;
}
return false;
}
// Adds all abundant numbers less than a limit to an array
std::vector<int> calculateAllAbundants(int limit)
{
int i;
int index = 1;
std::vector<int> abundants;
for (i = 1; i < limit; i++)
{
if (isAbundantNum(i))
{
abundants.at(index) = i;
index++;
cout << i << endl;
}
}
return abundants;
}
bool isSumOfAbundants(int num)
{
}
int main()
{
vector<int> abundants = calculateAllAbundants(30);
cout << abundants.at(1) << endl;
}