Advertisement
serega1112

mnogougolnik

Jan 8th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1.  
  2. n = int(input())
  3. dots = []
  4. while n:
  5.     dots.append(tuple(map(int, input().split())))
  6.     n -= 1
  7.  
  8. res = 0
  9.  
  10. for i in range(len(dots)):
  11.     x = abs(dots[i][0] - dots[i-1][0])
  12.     y = abs(dots[i][1] - dots[i-1][1])
  13.     if min(x, y) == 0:
  14.         res += max(x, y)
  15.     else:
  16.         while x % y > 0:
  17.             x, y = y, x % y
  18.         res += y
  19.  
  20. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement