-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathexer01a-max-div.cpp
More file actions
43 lines (28 loc) · 903 Bytes
/
Copy pathexer01a-max-div.cpp
File metadata and controls
43 lines (28 loc) · 903 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
/*
MAXIMUM NUMBER OF DIVISORS
*/
#include <iostream>
#include "mylib-time.hpp"
using namespace std;
int main() {
constexpr int RANGE_START = 1;
constexpr int RANGE_END = 100000;
int resValue = 0;
int resNumDiv = 0; // number of divisors of result
auto tpStart = mylib::HiResClock::now();
for (int i = RANGE_START; i <= RANGE_END; ++i) {
int numDiv = 0;
for (int j = i / 2; j > 0; --j)
if (i % j == 0)
++numDiv;
if (resNumDiv < numDiv) {
resNumDiv = numDiv;
resValue = i;
}
}
auto timeElapsed = mylib::HiResClock::getTimeSpan(tpStart);
cout << "The integer which has largest number of divisors is " << resValue << endl;
cout << "The largest number of divisor is " << resNumDiv << endl;
cout << "Time elapsed = " << timeElapsed.count() << endl;
return 0;
}