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
// pin.cpp
#include <iostream>
#include <vector>

using namespace std;

void solve();
int compute_divisors(int* dst, int number);

int divisors[100000];
int divisors_buffer[100000];

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

void solve()
{
    int n;
    cin >> n;
    int count = 0;
    int divisors_cnt = compute_divisors(divisors, n);
    for(int i = 0; i < divisors_cnt; i++)
    {
        int a = n - divisors[i];
        int buffer_count = compute_divisors(divisors_buffer, a);
        for(int j = 0; j < buffer_count; j++)
        {
            if(divisors_buffer[j] > divisors[i] && divisors_buffer[j] % divisors[i] == 0)
            {
                if(divisors_buffer[j] < a - divisors_buffer[j])
                {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

int compute_divisors(int* dst, int number)
{
    int x = number;
    int divisors_cnt = 0;
    int i = 1;
    while(i < x)
    {
        if(number % i == 0)
        {
            divisors_cnt++;
            *(dst++) = i;
            x = number / i;
            if(i > 1 && i < x)
            {
                divisors_cnt++;
                *(dst++) = x;
            }
        }
        i++;
    }
    return divisors_cnt;
}