Integer Division

If we find some number x is equal to others we've seen when divided by d, our new number will create a pair with each of the previous numerators that map to x/d. Therefore, we simply add the previous count and continue. Keep a map of numerator : quotient pairs for constant access to previous divisions.

integer.cpp
integer.py

_18
#include <iostream>
_18
#include <unordered_map>
_18
_18
using ll = long long;
_18
using namespace std;
_18
_18
int main () {
_18
int n;
_18
ll d;
_18
cin >> n >> d;
_18
unordered_map<ll,ll> v;
_18
ll total = 0;
_18
for (int i = 0; i < n; ++i) {
_18
ll x; cin >> x;
_18
total += v[x/d]++;
_18
}
_18
cout << total << '\n';
_18
}

If you found this solution helpful, consider leaving a star!