Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CF_TR4_A
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cmath>
- using namespace std;
- int gcd(int q, int w)
- {
- while (q != w)
- {
- if (q > w)
- q = q - w;
- else w = w - q;
- }
- return q;
- }
- int main()
- {
- long long x1, y1, x2, y2, k = 0;
- cin >> x1 >> y1 >> x2 >> y2;
- //scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
- if ((x1 == x2) || (y1 == y2))
- k = abs(x1 - x2) + abs(y1 - y2) + 1;
- else
- if ((y1*(x2 - x1) - x1*(y2 - y1)) != 0)
- k = gcd(abs(y2 - y1), gcd(abs(-(x2 - x1)), abs(y1*(x2 - x1) - x1*(y2 - y1)))) + 1;
- else
- k = gcd(abs(y2 - y1), abs(-(x2 - x1))) + 1;
- //cout << k;
- printf("%d", k);
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement