#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
int gcd(int a, int b) {
if(a == 0) return b;
if(b == 0) return a;
return gcd(b % a, a);
}
signed main() {
int a, b, n, t;
cin >> n >> a >> b;
int d = gcd(a, b + 1);
double sda = 1.0 * a / d * b;
if(sda <= 1e18) t = a / d * b;
else t = 1e18;
set<pii> v;
int l, r; bool gay = false;
for(int i = 0; i < n; i++) {
cin >> l >> r;
if(r - l + 1 >= t) {
gay = 1;
continue;
}
l %= t;
r %= t;
if(l <= r) {
// root->upt(l, r);
v.insert(MP(l, r));
}
else {
// root->upt(l, t - 1);
// root->upt(0, r);
v.insert(MP(l, t - 1));
v.insert(MP(0, r));
}
}
if(gay) {
cout << t << endl;
return 1;
}
int ans = 0;
l = 0, r = 0;
for(pii p : v) {
// cout << p.ff << ' ' << p.ss << endl;
if(r < p.ff) {
// cout << " + " << r - l + 1 << endl;
ans += (r - l + 1);
l = p.ff;
}
r = max(r, p.ss);
}
ans += (r - l + 1);
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
344 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |