-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path179.cpp
More file actions
46 lines (37 loc) · 1.04 KB
/
179.cpp
File metadata and controls
46 lines (37 loc) · 1.04 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
/* Project Euler Problem 179: https://projecteuler.net/problem=179 */
// Counts divisors for all integers up to the limit and totals adjacent pairs with equal divisor counts.
#include <iostream>
#include <map>
#include <chrono>
#include <cmath>
using namespace std;
void solve();
long limit = 1e7;
vector<long> nums(limit + 1, 2);
void solve() {
for (long i = 2; i < limit; i++) {
for (long j = i; i * j < limit; j++) {
if (i == j) {
nums[i * j]++;
}
else {
nums[i * j] += 2;
}
}
}
int ans = 0;
for (int i = 2; i < limit; i++) {
if (nums[i] == nums[i + 1]) {
ans++;
}
// cout<<i<<" "<<nums[i]<<" "<<i+1<<" "<<nums[i+1]<<endl;
}
cout << ans << endl;
}
int main() {
auto start = std::chrono::steady_clock::now();
solve();
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed = end - start;
std::cout << "Elapsed: " << elapsed.count() << " s\n";
}