Source Code
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll N = 1000000;
const ll M = N * N;

ll k;
int n;
vector<pll> a;

int main() {
    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        if (x <= N && x * x <= k) {
            a.emplace_back(y, x);
        }
    }
    sort(a.begin(), a.end());

    ll old = 0;
    ll answer = 0;
    set<ll> subs;
    vector<ll> temp;
    for (pll p : a) {
        ll y = p.second;
        ll x = y * y;

        ll current = old;
        if (x <= k) {
            temp.push_back(x);
            current += k / x;
        }

        for (ll z : subs) {
            if (abs(z * y) <= k && abs(z * x) <= k) {
                temp.push_back(-z * x);
                current += k / (-z * x);
            } else {
                break;
            }
        }

        for (ll z : temp) {
            subs.insert(z);
        }

        temp.clear();

        ll now = current - old;
        answer += now * p.first;
        old = current;
    }

    cout << answer << endl;
}
Copy
Number of the Beast Baraa_Armoush
GNU G++17
3 ms
1.1 MB
Wrong Answer
Test Case #1
1 ms
272 KB
Accepted
Input
4 10
2 300
3 66
5 100
13 32
Output
666
Judge Output
666
Checker Message
1 number(s): "666"
Test Case #2
0 ms
440 KB
Accepted
Input
2 50
3 10
7 21
Output
71
Judge Output
71
Checker Message
1 number(s): "71"
Test Case #3
3 ms
1.1 MB
Wrong Answer
Input
8944 1000000000000
530851 634109
437629 135449
760841 608005
987979 505317
567187 797505
115057 581792
986287 132112
788677 472337
209929 417283
972313 694722
65809 400083
710887 970135
432959 268565
920039 761441
375703 505835
988439 938996
257473 ...
Output
39180296146714
Judge Output
39179400996329
Checker Message
1st numbers differ - expected: '39179400996329', found: '39180296146714'