#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n, a, b;
cin>>n>>a>>b;
__int128 A = a, B = b;
__int128 CV = A * (B + 1) / __gcd(b + 1, a) / (B + 1) * B;
int cv = (int) CV;
__int128 ct = 1000000000000000001;
if(CV >= ct) cv = (int)ct;
//cout<<cv<<'\n';
map<int, int> mp;
bool ok = false;
for(int i = 1; i <= n; i++)
{
int st, dr;
cin>>st>>dr;
int cntupd = 0;
while(st <= dr && !ok)
{
int tl = st - st % cv + cv - 1;
if(tl > dr) tl = dr;
if(tl - st + 1 == cv)
{
ok = true;
break;
}
mp[st - cv * (st / cv)]++;
if((tl + 1) % cv == 0) mp[cv]--;
else mp[(tl + 1) - cv * ((tl + 1) / cv)]--;
st = tl + 1;
}
}
if(ok)
{
cout<<cv;
return 0;
}
int currsum = 0;
int st = -1, rez = 0;
for(auto it : mp)
{
currsum += it.second;
assert(currsum >= 0);
if(currsum > 0 && st == -1)
st = it.first;
else if(currsum == 0 && st != -1)
rez += it.first - st, st = -1;
}
assert(st == -1);
cout<<rez;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |