This page is still under construction.

Parts of this page are still being built. What you see may change.

Triangle

Time limit1sMemory limit128 MB

Summary
Count the lattice points strictly inside a lattice triangle given by its three vertices, for many test cases.
Level

Medium7 of 10

Topics
Geometry, Number theory, Math
Solved
No attempts yet

Problem

A lattice point is an ordered pair (x,y)(x, y) where both xx and yy are integers. Given the coordinates of the three vertices of a triangle, all of which are lattice points, count how many lattice points lie strictly inside the triangle. Points that lie on an edge or at a vertex do not count.

Input

The input contains several test cases. Each test case consists of six integers x1x_1, y1y_1, x2x_2, y2y_2, x3x_3, y3y_3, the coordinates of the vertices (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), and (x3,y3)(x_3, y_3). Every triangle is non-degenerate (it has positive area), and every coordinate satisfies −15000≤x1,y1,x2,y2,x3,y3≤15000-15000 \le x_1, y_1, x_2, y_2, x_3, y_3 \le 15000. The end of the input is marked by a test case with x1=y1=x2=y2=x3=y3=0x_1 = y_1 = x_2 = y_2 = x_3 = y_3 = 0, which must not be processed.

Output

For each test case, print the number of interior lattice points on its own line.

Examples2

  1. Example 1

    Input
    0 0 1 0 0 1
    0 0 5 0 0 5
    0 0 0 0 0 0
    
    Expected output
    0
    6
    
  2. Example 2

    Input
    0 0 10 0 0 10
    0 0 0 0 0 0
    
    Expected output
    36