Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution
- {
- using ll = long long;
- static const int MOD = 1e9 + 7;
- ll get_block_cnt(int i, const vector<int> &v)
- {
- // ll start = v[i];
- ll ret = 0;
- // ll n = v.back();
- ll n = v[i];
- for (ll l = 1; l <= n; l++) {
- ll d = n / l, r = n / d;
- int lb = lower_bound(v.begin(), v.end(), l) - v.begin();
- int ub = upper_bound(v.begin(), v.end(), r) - v.begin() - 1;
- // printf("lb:%d ub:%d d:%lld l:%lld, r:%lld\n", lb, ub, d, l, r);
- ret += (ub - lb + 1) * d;
- l = r;
- }
- // printf("i:%d ret:%lld\n", i, ret);
- return ret;
- }
- public:
- int sumOfFlooredPairs(vector<int> &ns)
- {
- int n = ns.size();
- sort(ns.begin(), ns.end());
- ll ret = 0;
- for (int i = 0; i < n; ++i) {
- ret += get_block_cnt(i, ns);
- }
- return ret;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement