#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=2e18;
ll n;
ll a,b;
map<ll,ll>mp;
ll l[1000002];
ll r[1000002];
int main()
{
cin>>n;cin>>a>>b;
ll d=__gcd(a,b+1);
ll m;
if(b>INF/(a/d))
{
m=INF;
}
else m=(a/d)*b;
//cout<<m<<endl;
for(ll i=1;i<=n;i++)
{
cin>>l[i]>>r[i];
}
for(ll i=1;i<=n;i++)
{
if((r[i]-l[i])>=m)
{
cout<<m<<endl;
return 0;
}
ll l1=l[i]%m;
ll r1=(r[i]+1)%m;
//cout<<l1<<" "<<r1<<endl;
if(l1<=r1)
{
mp[l1]++;
mp[r1]--;
}
else
{
mp[0]++;
mp[r1]--;
mp[l1]++;
mp[m]--;
}
}
ll ans=0,cur=0,last=-1,cur1=0;
for(auto xd:mp)
{
//if(xd.first==m)continue;
cur+=xd.second;
//cout<<"_"<<xd.first<<" "<<cur1<<endl;
if(cur1>0)
{
ans+=xd.first-last;
}
last=xd.first;
cur1=cur;
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |