#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
int gcd(int a,int b){
while (b) b^=a^=b^=a%=b;
return a;
}
signed main(){
int n,a,b;
cin>>n>>a>>b;
pair <int,int> p[n];
for (int i=0; i<n; i++) cin>>p[i].x>>p[i].y;
if (n==1){
__int128 f=p[0].y-p[0].x+1;
__int128 s=a*b/gcd(b,(b+1)%a);
int op=min(f,s);
cout<<op;
} else {
set <pair <int,int> > s;
for (int i=0; i<n; i++){
for (int t=p[i].x; t<=p[i].y; t++) s.insert({(t+t/b)%a,t%b});
}
cout<<s.size();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
58 ms |
12652 KB |
Output is correct |
3 |
Correct |
84 ms |
18156 KB |
Output is correct |
4 |
Correct |
2 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
8 ms |
1388 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
43 ms |
7020 KB |
Output is correct |
16 |
Correct |
40 ms |
7040 KB |
Output is correct |
17 |
Correct |
165 ms |
8684 KB |
Output is correct |
18 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
145 ms |
32364 KB |
Output is correct |
3 |
Correct |
170 ms |
32108 KB |
Output is correct |
4 |
Correct |
135 ms |
30772 KB |
Output is correct |
5 |
Execution timed out |
5104 ms |
78188 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1646 ms |
78572 KB |
Output is correct |
3 |
Runtime error |
3531 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1646 ms |
78572 KB |
Output is correct |
3 |
Runtime error |
3531 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1646 ms |
78572 KB |
Output is correct |
3 |
Runtime error |
3531 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
1864 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
58 ms |
12652 KB |
Output is correct |
3 |
Correct |
84 ms |
18156 KB |
Output is correct |
4 |
Correct |
2 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
8 ms |
1388 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
43 ms |
7020 KB |
Output is correct |
16 |
Correct |
40 ms |
7040 KB |
Output is correct |
17 |
Correct |
165 ms |
8684 KB |
Output is correct |
18 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |