#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
lld GCD(lld x, lld y){
if(y==0)return x;
return GCD(y,x%y);
}
int main(){
srand(time(NULL));
lld n,A,B;
cin>>n>>A>>B;
/*n=1;
A=rand()%100;
B=rand()%100;*/
lld l[n];
lld r[n];
rep(i,0,n){
cin>>l[i]>>r[i];
/*l[i]=rand()%200;
r[i]=rand()%200;
if(l[i]>r[i])swap(l[i],r[i]);*/
}
lld D=GCD(A,B+1);
D=A/D;
if(n>1){
set<pair<lld,lld> >s;
rep(i,0,n){
for(lld j=l[i];j<=r[i];j++){
s.insert(pair<lld,lld>((j+(j/B))%A,j%B));
}
}
cout<<s.size()<<endl;
return 0;
}
cout<<min(r[0]-l[0]+1,D*B)<<endl;
//cout<<s.size()<<" "<<min(r[0]-l[0]+1,D*B)<<" "<<A<<" "<<B<<" "<<l[0]<<" "<<r[0]<<endl;
//trav(a,s)cout<<a.first<<" "<<a.second<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
91 ms |
12500 KB |
Output is correct |
3 |
Correct |
151 ms |
18104 KB |
Output is correct |
4 |
Correct |
4 ms |
888 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
13 ms |
1272 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
276 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
64 ms |
7016 KB |
Output is correct |
16 |
Correct |
62 ms |
7004 KB |
Output is correct |
17 |
Correct |
296 ms |
8600 KB |
Output is correct |
18 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
205 ms |
32332 KB |
Output is correct |
3 |
Correct |
226 ms |
32104 KB |
Output is correct |
4 |
Correct |
200 ms |
30624 KB |
Output is correct |
5 |
Execution timed out |
5064 ms |
80692 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2817 ms |
79604 KB |
Output is correct |
3 |
Execution timed out |
5085 ms |
478060 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2817 ms |
79604 KB |
Output is correct |
3 |
Execution timed out |
5085 ms |
478060 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2817 ms |
79604 KB |
Output is correct |
3 |
Execution timed out |
5085 ms |
478060 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Runtime error |
2273 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
91 ms |
12500 KB |
Output is correct |
3 |
Correct |
151 ms |
18104 KB |
Output is correct |
4 |
Correct |
4 ms |
888 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
13 ms |
1272 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
276 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
64 ms |
7016 KB |
Output is correct |
16 |
Correct |
62 ms |
7004 KB |
Output is correct |
17 |
Correct |
296 ms |
8600 KB |
Output is correct |
18 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |