#include <iostream>
#include <numeric>
#include <array>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
ll n, a, b, l, r, x, y, z;
string S;
vector <array<__int128, 2>> V;
__int128 cl, cr, k, p, f;
void print(__int128 v) {
S.clear();
while (v) {
S.push_back(char('0'+v%10));
v /= 10;
}
if (S.empty()) S.push_back('0');
reverse(S.begin(), S.end());
cout << S << '\n';
}
int main() {
cin >> n >> a >> b;
x = (b+1)%a, y = a;
z = gcd(x, y);
k = y/z;
k *= b;
for (int i=0; i<n; ++i) {
cin >> l >> r;
cl = l, cr = r;
cr = min(cl+k-1, cr);
cl %= k;
cr %= k;
if (cl > cr) {
V.push_back({cl, k-1});
V.push_back({0, cr});
}
else V.push_back({cl, cr});
}
sort(V.begin(), V.end());
p = -1;
for (auto [l, r] : V) {
if (l <= p && p <= r) {
f += r-p;
}
else if (p < l) {
f += r-l+1;
}
p = max(p, r);
}
print(f);
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:28:7: error: 'gcd' was not declared in this scope
28 | z = gcd(x, y);
| ^~~
strange_device.cpp:45:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
45 | for (auto [l, r] : V) {
| ^