- P59's solution
-
题解 P59
- @ 2026-2-7 21:51:03
公式就是:
$$\gcd(\lvert x_2 - x_1 \rvert, \lvert y_2 - y_1 \rvert) + 1$$AC code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll x1, y1, x2, y2;
while (cin >> x1 >> y1 >> x2 >> y2) {
ll dx = abs(x2 - x1);
ll dy = abs(y2 - y1);
ll g = __gcd(dx, dy);
if (dx == 0 && dy == 0) {
cout << 0 << endl;
} else {
cout << g - 1 << endl;
}
}
return 0;
}