-
Notifications
You must be signed in to change notification settings - Fork 0
/
p21.c
39 lines (35 loc) · 754 Bytes
/
p21.c
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
//
// main.c
// Learning2
//
// Created by Aditya Gudibanda on 8/28/14.
// Copyright (c) 2014 Aditya Gudibanda. All rights reserved.
//
int sumofdivisors(int n);
main()
{
long int answer;
int sums[10000];
for (int i = 0; i < 10000; ++i) {
sums[i] = sumofdivisors(i);
}
for (int j = 1; j <= 9999; ++j) {
for (int k = 1; k <= 9999; ++k) {
if (sums[j] == k && sums[k] == j && j != k) {
printf("%d \t %d \n", j, k);
answer = answer +j +k;
}
}
}
printf("%lu\n", answer/2);
}
int sumofdivisors(int n)
{
int sum = 0;
for (int i = 1; i <= n/2; ++i) {
if (n % i == 0) {
sum = sum + i;
}
}
return sum;
}