#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef int64_t llo;
#define a first
#define b second
#define endl "\n"
llo gcd(llo kk,llo ll){
if(ll==0){
return kk;
}
return gcd(ll,kk%ll);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n,a,b;
cin>>n>>a>>b;
llo x;
pair<llo,llo> it;
x=b;
x*=(a/gcd(a,b+1));
/* if((b+1)%a==0){
x=b;
}
else{
x=a*b;
}*/
llo aa,bb;
set<pair<llo,llo>> ac;
for(llo i=0;i<n;i++){
cin>>aa>>bb;
/*if(bb-aa+1>=x){
cout<<x<<endl;
return 0;
}*/
if(bb-aa+1>=x){
while(true){
int y=1;
}
}
aa%=x;
bb%=x;
if(bb<aa){
ac.insert(mp(aa,x-1));
ac.insert(mp(0,bb));
}
else{
ac.insert(mp(aa,bb));
}
}
vector<pair<llo,llo>> prev;
for(auto cc:ac){
if(prev.size()==0){
prev.pb(cc);
}
else{
if(cc.a>prev.back().b){
prev.pb(cc);
}
else{
prev[prev.size()-1].b=max(prev[prev.size()-1].b,cc.b);
}
}
}
llo tot=0;
for(llo i=0;i<prev.size();i++){
tot+=prev[i].b-prev[i].a+1;
}
cout<<tot<<endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:43:9: warning: unused variable 'y' [-Wunused-variable]
int y=1;
^
strange_device.cpp:72:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<prev.size();i++){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5078 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5077 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5080 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5067 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5067 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5067 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5071 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5078 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |