#include <bits/stdc++.h>
using namespace std;
# define int long long
# define fir first
# define sec second
# define pb push_back
const int cnst = 2e5+5;
bool mutipletestcase = 0;
//bool debug = false;
int gcd(int a, int b) {return b ? gcd(b, a%b): a;}
int lcm(int a, int b) {return a/gcd(a, b)*b;}
void solve() {
int n, a, b; cin >> n >> a >> b;
int gcdnum = gcd(a, b);
a /= gcdnum, b /= gcdnum;
int val = a*b;
if(a*b <= 1e6) {
int ans = 0;
int get[val*2+5];
memset(get, 0, sizeof(get));
while(n--) {
int x, y; cin >> x >> y;
int len = y-x+1;
if(len > a*b) ans = a*b;
x %= val;
y %= val;
if(y < x) y += val;
// cerr << x << " " << y << endl;
get[x]+=1, get[y+1] -= 1;
}
if(ans == a*b) cout << ans << endl;
else {
bool yes[val+5];
memset(yes, 0, sizeof(yes));
for(int i = 1; i<=2*val; i++) {
get[i] += get[i-1];
cerr << get[i] << " ";
if(get[i]) yes[i%val] = 1;
}
for(int i = 0; i<val; i++) {
if(yes[i]) ans++;
}
cout << ans << endl;
}
return;
}
if(b == 1) {
}
set<pair<int, int>> st;
while(n--) {
int x, y; cin >> x >> y;
for(int i = x; i<=y; i++) {
st.insert({(i+i/b)%a, i%b});
}
}
cout << st.size() << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
int t = 1;
if(mutipletestcase) cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |