-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler021.cpp
More file actions
82 lines (71 loc) · 1.38 KB
/
euler021.cpp
File metadata and controls
82 lines (71 loc) · 1.38 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
4/29/2012 5:24 (only working on it til i leave for dinner)
amicable pairs
first thoughts- use a function to find divisors and sum them, store original number and sum in container next to each other, be able to look up at the end
*/
#include <iostream>
using namespace std;
int divisorSum(int original){
//find divisors
int sum=1;
for (int a=2;a<original;a++)
{
if (original%a==0)
{
sum+=a;
}
}
return sum;
}
int main(){
const int size=10000;
int matrix[size][2];
for (int n=0;n<size;n++)
{
matrix[n][0]=n;
matrix[n][1]=divisorSum(n);
}
cout << matrix[220][1] << " " << matrix[220][0] << endl;
cout << matrix[284][1] << " " << matrix[284][0] << endl;
int amicable[50]={0};
int count =0;
for (int shit=0;shit<10000;shit++)
{
if (matrix[shit][1]<10000){
if (matrix[shit][0]==matrix[ (matrix[shit][1]) ][1] )
{
if (matrix[shit][0] != matrix[shit][1])
{
amicable[count]=matrix[shit][0];
count++;
amicable[count]=matrix[shit][1];
count++;
}
}
if (count>49)
break;
}
}
for (int tits=0;tits<50;tits++)
{
for (int balls=tits+1;balls<50;balls++)
{
if (amicable[tits]==amicable[balls])
{
amicable[balls]=0;
}
}
}
int sum=0;
for (int fuck1=0;fuck1<50;fuck1++)
{
sum+=amicable[fuck1];
}
for (int fuck=0;fuck<50;fuck++)
{
cout << amicable[fuck] <<" ";
}
cout << "\n\n\nanswer:"<<sum;
getchar();
return 0;
}