Pick's Theorem states that if we have a polygon with lattice points as vertices, then:
where A is the area of the polygon, I is the number of lattice points inside of the polygon, and B is the number of lattice points on the boundary of the polygon. We are asked to find I.
Thus, if we find A and B, w can use Pick's Theorem to find I. The area is simply M * P / 2. We can find B by noting that the number of points that lie on a line with lattice endpoints (W,X) and (Y,Z) is 1 + gcd(|Y - W|, |Z - X|). We find the number of boundary points on each edge of the triangle, and subtract 3 (because we are double counting the vertices of the triangle) to find B.