-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler23.cpp
More file actions
49 lines (44 loc) · 895 Bytes
/
euler23.cpp
File metadata and controls
49 lines (44 loc) · 895 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
44
45
46
47
48
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int testAbundant(long n){
long sum=0;
for(long i=1;i<((n/2)+1);i++){
//cout<<i<<" <-- i "<< int(n%i) <<" <-- n%i\n";
if((n%i)==0)
sum+=i;
}
//cout<<"testAbundant"<<sum<<' '<<n<<'\n';
if(sum>n)return 1;
return 0;
}
int test(long num){
long a,b;
for(long i=12;i<((num/2)+1);i++){
a=num-i;
b=i;
//cout<<a << ' '<<b<<'\n';
if(testAbundant(a) && testAbundant(b)){
return 1;
}
}
return 0;
}
int main() {
long sum=0;
for(int i=0;i<28123;i++){
if(!test(i)){
sum+=i;
cout<<"\033[1;31m"<<i<<"\033[0m\t";
}
else
{
cout<<i<<'\t';
}
}
cout<<"\n\n"<<sum<<'\n';
return 0;
}