#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
const int INF=9e18;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;cin>>t;
int a,b;cin>>a>>b;
int m=0;
int g=__gcd(a,b+1);
__int128 tmp=a*b/g;
if(tmp>INF){
m=INF;
}
else{
m=tmp;
}
vector<pair<int,int>> v;
for(int i=0;i<t;i++){
int l,r;cin>>l>>r;
if(r%m<l%m){
v.push_back({l%m,m-1});
v.push_back({0,r%m});
}
else{
v.push_back({l%m,r%m});
}
}
sort(all(v));
int ans=0;
int l=0;
for(pair<int,int> p:v){
p.first=max(p.first,l);
if(p.second<p.first){
continue;
}
ans+=(p.second-p.first+1);
l=p.second+1;
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
728 KB |
Output is correct |
3 |
Correct |
5 ms |
728 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
49 ms |
5700 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Incorrect |
1 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 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
296 ms |
16860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
457 ms |
16832 KB |
Output is correct |
3 |
Correct |
417 ms |
16876 KB |
Output is correct |
4 |
Correct |
418 ms |
17584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
457 ms |
16832 KB |
Output is correct |
3 |
Correct |
417 ms |
16876 KB |
Output is correct |
4 |
Correct |
418 ms |
17584 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
423 ms |
17580 KB |
Output is correct |
7 |
Correct |
439 ms |
17676 KB |
Output is correct |
8 |
Correct |
430 ms |
17712 KB |
Output is correct |
9 |
Correct |
452 ms |
17572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
457 ms |
16832 KB |
Output is correct |
3 |
Correct |
417 ms |
16876 KB |
Output is correct |
4 |
Correct |
418 ms |
17584 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
49 ms |
5608 KB |
Output is correct |
7 |
Correct |
53 ms |
5668 KB |
Output is correct |
8 |
Correct |
52 ms |
5628 KB |
Output is correct |
9 |
Correct |
54 ms |
5724 KB |
Output is correct |
10 |
Correct |
48 ms |
5636 KB |
Output is correct |
11 |
Correct |
45 ms |
5724 KB |
Output is correct |
12 |
Correct |
44 ms |
5720 KB |
Output is correct |
13 |
Correct |
45 ms |
5700 KB |
Output is correct |
14 |
Correct |
45 ms |
5708 KB |
Output is correct |
15 |
Correct |
49 ms |
5692 KB |
Output is correct |
16 |
Correct |
48 ms |
5708 KB |
Output is correct |
17 |
Correct |
57 ms |
5804 KB |
Output is correct |
18 |
Correct |
445 ms |
17688 KB |
Output is correct |
19 |
Correct |
427 ms |
17636 KB |
Output is correct |
20 |
Correct |
457 ms |
17492 KB |
Output is correct |
21 |
Correct |
59 ms |
5696 KB |
Output is correct |
22 |
Correct |
45 ms |
5628 KB |
Output is correct |
23 |
Correct |
142 ms |
18452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
44 ms |
2616 KB |
Output is correct |
3 |
Correct |
46 ms |
2612 KB |
Output is correct |
4 |
Correct |
481 ms |
16828 KB |
Output is correct |
5 |
Correct |
44 ms |
2548 KB |
Output is correct |
6 |
Correct |
45 ms |
2560 KB |
Output is correct |
7 |
Correct |
47 ms |
2544 KB |
Output is correct |
8 |
Correct |
44 ms |
2588 KB |
Output is correct |
9 |
Correct |
42 ms |
2636 KB |
Output is correct |
10 |
Correct |
44 ms |
2560 KB |
Output is correct |
11 |
Correct |
45 ms |
2552 KB |
Output is correct |
12 |
Correct |
37 ms |
2576 KB |
Output is correct |
13 |
Correct |
46 ms |
2540 KB |
Output is correct |
14 |
Correct |
471 ms |
16808 KB |
Output is correct |
15 |
Correct |
45 ms |
2580 KB |
Output is correct |
16 |
Correct |
444 ms |
18200 KB |
Output is correct |
17 |
Correct |
437 ms |
18220 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
728 KB |
Output is correct |
3 |
Correct |
5 ms |
728 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
49 ms |
5700 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |