#include <bits/stdc++.h>
#define TASK "aksdjaskd"
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define all(C) C.begin(), C.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INT_LIM = 2147483647;
const ll LL_LIM = 9223372036854775807;
template <typename X> bool minimize(X &x, const X &y) {if (x>y){x = y; return true;}return false;}
template <typename X> bool maximize(X &x, const X &y) {if (x<y){x = y; return true;}return false;}
///------------------------------------------///
int n;
ll a,b, maxr;
pair<ll,ll> c[1000005];
void inp()
{
cin >> n >> a >> b;
maxr = 0;
FOR(i, 1, n)
{
cin >> c[i].fi >> c[i].se;
}
maxr = c[n].se;
}
vector<pair<ll,ll>> f;
vector<pair<ll,ll>> f2;
void solve()
{
ll g = __gcd(a, b+1);
a/=g;
ll period = 0;
if (a<=maxr/b) period = a*b;
else period = maxr+1;
FOR(i, 1, n)
{
ll l = c[i].fi%period, r = c[i].se%period;
if (l<=r) f.pb(mp(l,r));
else
{
f.pb(mp(l, period-1));
f.pb(mp(0, r));
}
}
sort(all(f));
ll ans = 0;
f2.pb(mp(-1, -2));
for (auto r:f)
{
if (r.fi>f2.back().se) f2.pb(r);
else f2.back().se = max(f2.back().se, r.se);
}
for (auto r:f2) ans+= r.se-r.fi+1;
cout << ans;
}
signed main()
{
///--------------------------///
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen(TASK".INP","r")!=NULL)
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
///--------------------------///
int NTEST = 1;
bool codeforces = 0;
if (codeforces) cin >> NTEST;
while (NTEST--)
{
inp();
solve();
}
return 0;
}
///------------------------------------------///
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int main()':
strange_device.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(TASK".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen(TASK".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |