-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path021.cpp
23 lines (19 loc) · 847 Bytes
/
021.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Problem URL: https://projecteuler.net/problem=21
// ---------------------------------------------------------------------------------
// Amicable numbers: numbers whose sum of divisors is equal to each other (but the numbers are not the same)
// ---------------------------------------------------------------------------------
// Find the sum of all amicable numbers below 10,000
#include <iostream>
#include "extras/euler_funcs.h" // for sum_divisors()
int main() {
const int Limit = 10000;
int amicable_sum = 0;
for (int a = 1; a < Limit; a++) {
int b = sum_divisors(a);
if (a != b && a == sum_divisors(b)) { // make sure a and b aren't the same
amicable_sum += a;
}
}
std::cout << "Sum of all amicable numbers under " << Limit << ": " << amicable_sum << std::endl;
return 0;
}