This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |