Under construction

Still being built. Things may change

lattice

Interview

Time limit1sMemory limit512 MB

Summary
Given three non-collinear integer points with coordinates up to 2^1024, count the lattice points on the triangle's perimeter, including the vertices.
Level

Medium4 of 10

Topics
Math, Number theory, Geometry, Implementation
Solved
No attempts yet

Problem

Write a function P1:

  • A point (x,y)(x,y) is called a lattice point iff both xx and yy are integers.

  • input parameter: integers x1, y1, x2, y2, x3, y3

    • Three points (x1, y1), (x2, y2), (x3, y3) are not on a same straight line.
    • The absolute value of each input parameter is less than or equal to 210242^{1024}.
  • return value: the number of the lattice points (including vertexes) on the perimeter of the triangle with three vertexes (x1, y1), (x2, y2), (x3, y3)

    • For example, if a triangle has vertexes (0,0),(2,2),(3,0)(0,0),(2,2),(3,0) then its perimeter has 6 lattice points: (0,0),(1,1),(2,2),(3,0),(2,0),(1,0)(0,0),(1,1),(2,2),(3,0),(2,0),(1,0).

Examples1

  1. Example 1

    Input
    0 0 1 0 0 1
    
    Expected output
    3