Submission #1282130

#TimeUsernameProblemLanguageResultExecution timeMemory
1282130kawhietSpiderman (COCI20_spiderman)C++20
14 / 70
353 ms10208 KiB
#include <bits/stdc++.h>
using namespace std;

constexpr int N = 1e6 + 1;

int cnt[N];

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 42
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        cnt[h[i]]++;
    }
    vector<int> res(N);
    for (int i = 0; i < n; i++) {
        if (h[i] <= k) {
            res[i] = (h[i] == k ? n - 1 : 0);
            continue;
        }
        int x = h[i] - k;
        vector<int> d;
        for (int f = 1; f * f <= x; f++) {
            if (x % f == 0) {
                d.push_back(f);
                if (f * f != x) {
                    d.push_back(x / f);
                }
            }
        }
        dbg(d);
        for (auto f : d) {
            if (f == 1) continue;
            res[i] += cnt[f];
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << ' ';
    }
    cout << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...