#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
const ll inf = 1e18+5;
ll n, a, b, loop, l, r, out;
vector<pii> v;
ll gcd(ll c1, ll c2) {
if (!(max(c1,c2)%min(c1,c2))) return min(c1, c2);
return gcd(min(c1,c2), max(c1,c2)%min(c1,c2));
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> a >> b;
a/=gcd(a,b+1);
while (a>0) {
loop += (a%10)*b;
if (loop>inf) break;
a/=10;
}
while (n--) {
cin >> l >> r, l%=loop, r%=loop;
if (l>r) v.push_back({0,r}), v.push_back({l,loop-1});
else v.push_back({l,r});
}
sort(v.begin(), v.end(), greater<pii>());
while (v.size()>=2) {
pii x=v.back(); v.pop_back();
pii y=v.back();
if (x.second >= y.first) v.pop_back(), v.push_back({x.first, max(x.second, y.second)});
else out+=x.second-x.first+1;
}
cout << out + v[0].second-v[0].first+1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
4 ms |
600 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
412 ms |
16872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
412 ms |
16872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
412 ms |
16872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
41 ms |
2512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
4 ms |
600 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |