Isosceles Triangles
Time limit2sMemory limit128 MB
Count all isosceles triangles (non-collinear, at least two equal sides) formed by points in an N by M lattice grid, N and M up to 200.
- Level
Hard8 of 10
- Topics
- Geometry, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
A triangle is isosceles if two of its side lengths are equal.
There are lattice points arranged in N rows and M columns. The three vertices of a triangle must be distinct lattice points, and three collinear points do not form a triangle.
Two triangles are different if at least one vertex position differs. Count how many different isosceles triangles can be formed from the given lattice points.
Input
The first line contains two positive integers N and M separated by a space. Both N and M are at most 200.
Output
Print the number of different isosceles triangles.
Hint
For a 2 by 3 grid of lattice points, the following 10 arrangements are possible.
XX. XX. .X. X.. X.X
X.. .X. XX. XX. .X.
.XX .XX ..X .X. .X.
.X. ..X .XX .XX X.X