#include <bits/stdc++.h>
using namespace std;
int main(){
long long n, a, b, ans=0;
cin>>n>>a>>b;
if (log(a)+log(b)>log(__gcd(a,b+1))+log(1e18)){
for (int i =0; i<n; ++i){
long long li,ri;cin>>li>>ri;
ans += ri-li+1;
}
cout<<ans<<endl;
return 0;
}
long long s = a/__gcd(a,b+1)*b;
set<pair<long long, long long>> st;
for (int i = 0; i<n;++i){
int li, ri; cin >> li >> ri;
if (ri-li+1>=s) st.insert({0,s-1});
else if (ri%s<li%s){
st.insert({0,ri%s});
st.insert({li%s,s-1});
}
else st.insert({li%s,ri%s});
}
ans =s;
long long x = -1;
for (auto el : st) {
ans -= max (el.first-x-1, 0LL);
x = max (x, el.second);
}
ans -= s-1-x;
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Incorrect |
28 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Incorrect |
28 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Incorrect |
28 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
4 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |