/* ** *** In the name of God *** ** */
// Only Haider is Amir al-Momenin
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 1;
// #define endl '\n'
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, A, B;
cin >> n >> A >> B;
ll x = 1ll * A / __gcd(A, B + 1);
if (x <= inf / B) x *= B;
else x = inf;
vector<pair<ll, ll>> b;
while (n--) {
ll l, r;
cin >> l >> r;
// l--, r--;
if (r - l + 1 >= x) return cout << x, 0;
l %= x, r %= x;
if (r >= l) b.push_back({l, r});
else b.push_back({l, x - 1}), b.push_back({0, r});
}
sort(b.begin(), b.end());
ll p = 0, ans = x;
// cout << x << endl;
for (auto i : b) {
ll l = i.first, r = i.second;
// cout << l << ' ' << r << endl;
if (l > p) ans -= (l - p);
p = r + 1;
}
ans -= (x - p);
cout << ans;
return 0;
}
/*
_ _ _ _ _ _ _ _ _ _ _ _
/ / \ / / | / / |
/``````\ \ |`````| | |`````| |
/ \ \ | | | | | |
/ \ \ | | | | | |
/ /\ \ \ | | | | | |
/ / /\ \ \ | | | | | |
/ / / \ \ \ | | | | | |
/ / /_ _ \ \ \ | | | | | |
/ /_ _ _ _ \ \ \ | | | | | |
/ \ \ | | |_ _ _ _ | | |
/ _ _ _ _ _ _ _ \ \ | | / /| | | |
/ / / \ \ \ | |/_ _ _ _ / | | | |
/ / / \ \ / | | / | | /
/_ _ _/_/ \_ _ _\/ |_ _ _ _ _ _ _ _|/ |_ _ _|/
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
5 ms |
592 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
487 ms |
16840 KB |
Output is correct |
3 |
Correct |
459 ms |
16912 KB |
Output is correct |
4 |
Correct |
442 ms |
16804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
487 ms |
16840 KB |
Output is correct |
3 |
Correct |
459 ms |
16912 KB |
Output is correct |
4 |
Correct |
442 ms |
16804 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
484 ms |
16840 KB |
Output is correct |
7 |
Correct |
459 ms |
16788 KB |
Output is correct |
8 |
Correct |
466 ms |
16892 KB |
Output is correct |
9 |
Correct |
545 ms |
17040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
487 ms |
16840 KB |
Output is correct |
3 |
Correct |
459 ms |
16912 KB |
Output is correct |
4 |
Correct |
442 ms |
16804 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
45 ms |
2508 KB |
Output is correct |
7 |
Correct |
47 ms |
2460 KB |
Output is correct |
8 |
Correct |
55 ms |
2496 KB |
Output is correct |
9 |
Correct |
56 ms |
2496 KB |
Output is correct |
10 |
Correct |
49 ms |
2576 KB |
Output is correct |
11 |
Correct |
46 ms |
2464 KB |
Output is correct |
12 |
Correct |
43 ms |
2448 KB |
Output is correct |
13 |
Correct |
47 ms |
2508 KB |
Output is correct |
14 |
Correct |
45 ms |
2404 KB |
Output is correct |
15 |
Incorrect |
58 ms |
2476 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
49 ms |
2412 KB |
Output is correct |
3 |
Correct |
48 ms |
2504 KB |
Output is correct |
4 |
Correct |
629 ms |
16828 KB |
Output is correct |
5 |
Correct |
51 ms |
2368 KB |
Output is correct |
6 |
Correct |
47 ms |
2428 KB |
Output is correct |
7 |
Correct |
60 ms |
2492 KB |
Output is correct |
8 |
Correct |
49 ms |
2412 KB |
Output is correct |
9 |
Correct |
48 ms |
2504 KB |
Output is correct |
10 |
Correct |
48 ms |
2480 KB |
Output is correct |
11 |
Correct |
48 ms |
2492 KB |
Output is correct |
12 |
Correct |
45 ms |
2492 KB |
Output is correct |
13 |
Correct |
50 ms |
2468 KB |
Output is correct |
14 |
Incorrect |
550 ms |
16748 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
5 ms |
592 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |