-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 12.cpp
More file actions
53 lines (42 loc) · 822 Bytes
/
Copy pathProblem 12.cpp
File metadata and controls
53 lines (42 loc) · 822 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
49
50
51
52
53
#include<iostream.h>
#include<cmath>
//#define DEBUG
int numOfFactors(long long num);
int trinum(long long num);
const int range = 500;
int main(){
long long i;
for(i = 1; numOfFactors(trinum(i)) <= 500; i++){
}
cout << trinum(i) << endl;
system("PAUSE");
}
int numOfFactors(long long num){
int facts = 0;
if(num == 1){
return (1);
} else if (num > 1) {
for(int i = 2; i < sqrt(num); i++){
if(num % i == 0){
facts++;
}
}
facts += 1;
facts = facts * 2;
if (sqrt(num) == ceil(sqrt(num) - 0.5)){
facts++;
}
return (facts);
} else if (num < 0){
return (numOfFactors(abs(num)));
} else {
return (0);
}
}
int trinum(long long num){
long long sum = 0;
for(long long i = 1; i <= num; i++){
sum += i;
}
return (sum);
}