Advertisement
Tolyamba

Untitled

Jun 14th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. // CF_TR4_A
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int gcd(int q, int w)
  9. {
  10.     while (q != w)
  11.     {
  12.         if (q > w)
  13.             q = q - w;
  14.         else w = w - q;
  15.     }
  16.     return q;
  17. }
  18.  
  19. int main()
  20. {
  21.     long long x1, y1, x2, y2, k = 0;
  22.     cin >> x1 >> y1 >> x2 >> y2;
  23.     //scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  24.  
  25.     if ((x1 == x2) || (y1 == y2))
  26.         k = abs(x1 - x2) + abs(y1 - y2) + 1;
  27.     else
  28.     if ((y1*(x2 - x1) - x1*(y2 - y1)) != 0)
  29.         k = gcd(abs(y2 - y1), gcd(abs(-(x2 - x1)), abs(y1*(x2 - x1) - x1*(y2 - y1)))) + 1;
  30.     else
  31.         k = gcd(abs(y2 - y1), abs(-(x2 - x1))) + 1;
  32.  
  33.     //cout << k;
  34.     printf("%d", k);
  35.     //system("pause");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement