#include<bits/stdc++.h> #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; }
signedmain() { int n = read(), l = read(); std::vector<int> a(n); for(int i = 0; i < n; i++) { a[i] = l + i; } std::function<bool(int, int)> cmp = [&](int x, int y) { return std::abs(x) < std::abs(y); }; std::sort(a.begin(), a.end(), cmp); int res = 0; for(int i = 1; i < a.size(); i++) res += a[i]; std::cout << res << "\n"; return0; }
#include<bits/stdc++.h> #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; }
signedmain() { int a = read(), b = read(), c = read(), d = read(); auto cal = [&](int x) -> int { int res = x; int t = (c * d) / std::__gcd(c, d); res -= x / c; res -= x / d; res += x / t; return res; }; std::cout << cal(b) - cal(a - 1); return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; }
constint N = 1e5 + 10;
signedmain() { int n = read(); vector<int> p(2 * N + 1); for(int i = 1; i <= 2 * N; i++) p[i] = i; function<int(int)> find = [&](int x) { return x == p[x] ? x : p[x] = find(p[x]); }; for(int i = 0; i < n; i++) { int x = read(), y = read(); x = find(x), y = find(y + N); if(x != y) { p[x] = y; } } vector<int> r(2 * N + 1), c(2 * N + 1); for(int i = 1; i <= N; i++) c[find(i)]++; for(int i = N + 1; i <= 2 * N; i++) r[find(i)]++; int res = 0; for(int i = 1; i <= 2 * N; i++) res += r[i] * c[i]; std::cout << res - n << "\n"; return0; }