-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathpairs-again.cpp
65 lines (53 loc) · 1.26 KB
/
pairs-again.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
// Mathematics > Number Theory > Satisfactory Pairs
// How many pairs of integers give a solution?
//
// https://www.hackerrank.com/challenges/pairs-again/problem
// https://www.hackerrank.com/contests/w26/challenges/pairs-again
// challenge id: 27017
//
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<vector<unsigned>> divs;
vector<bool> used;
unsigned n;
cin >> n;
divs.resize(n + 1);
used.resize(n + 1);
// calcule les diviseurs de i ∈ [1, n]
for (unsigned i = 1; i <= n; i++)
{
for (unsigned j = i; j <= n; j += i)
{
divs[j].push_back(i);
}
}
unsigned nb = 0;
for (unsigned a = 1; a <= n; a++)
{
for (unsigned x = 1; a * x <= n; x++)
{
for (unsigned d : divs[n - a * x])
{
if (a < d)
{
if (!used[d])
{
used[d] = true;
nb++;
}
}
}
}
for (unsigned x = 1; a * x <= n; x++)
{
for (unsigned d : divs[n - a * x])
{
used[d] = false;
}
}
}
cout << nb << endl;
return 0;
}