2 条题解
-
0
公式就是:
$$\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; } -
0
由数论知识可知,答案为(其中 表示最大公因数,此处 ):
#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; }
- 1
信息
- ID
- 59
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 11
- 已通过
- 4
- 上传者