- P59's solution
P59's Solution
- 2025-9-14 19:52:41 @
由数论知识可知,答案为(其中 表示最大公因数,此处 ):
#include <bits/stdc++.h>
using namespace std;
#define y1 Y1
int main()
{
int x1, y1, x2, y2;
while (cin >> x1 >> y1 >> x2 >> y2)
{
int dx = abs(x1 - x2), dy = abs(y1 - y2);
if (1ll * dx * dy == 0) cout << max(max(dx, dy) - 1, 0) << endl;
else cout << __gcd(dx, dy) - 1 << endl;
}
return 0;
}