-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEulerProb12.cpp
More file actions
42 lines (34 loc) · 866 Bytes
/
EulerProb12.cpp
File metadata and controls
42 lines (34 loc) · 866 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
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int i = 1;
long long int sum = 0;
int count = 0;
long long int sum_of_series(int);
while(count < 500){
sum = sum_of_series(i);
//cout<<sum<<endl;
count = 0;
for( int j = 1; j <= sqrt(sum); j++){
if((sum) % j == 0){
if(j*j == sum){
count++;
}
else {
count = count + 2;
}
if (count >= 500){
cout<<sum<<" ";
break;
}
}
}
i++;
}
}
long long int sum_of_series(int num_terms) {
long long int sum;
sum = (num_terms*(num_terms + 1))/2;
return sum;
}