Загрузка данных


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    const long long LIMIT = 1000000000LL;
    vector<long long> p;

    // Generate pentagonal numbers
    for (long long n = 1; ; n++) {
        long long x = n * (3 * n - 1) / 2;
        if (x > LIMIT) break;
        p.push_back(x);
    }

    int n = p.size();
    long long ans1 = 0;
    long long ans2 = 0;

    // Case 1: a < b < c, a + b = c
    for (int k = 2; k < n; k++) {
        int i = 0;
        int j = k - 1;

        while (i < j) {
            long long sum = p[i] + p[j];

            if (sum == p[k]) {
                ans1++;
                i++;
                j--;
            }
            else if (sum < p[k]) {
                i++;
            }
            else {
                j--;
            }
        }
    }

    // Case 2: a = b < c, 2*a = c
    for (int i = 0; i < n; i++) {
        long long x = 2 * p[i];

        if (x > LIMIT) break;

        if (binary_search(p.begin(), p.end(), x)) {
            ans2++;
        }
    }

    cout << ans1 << '\n';
    cout << ans2 << '\n';

    return 0;
}