Grid paper and triangles
Time limit2sMemory limit512 MB
Count ordered triples of lattice points in a (w+1) by (h+1) grid whose triangle has positive integer area, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math, Number theory, Geometry
- Solved
- No attempts yet
Problem
A sheet of grid paper is wide and tall. Every integer coordinate with and carries a dot, so the sheet holds dots.
Write a program that counts the triangles you can build by joining three dots of the grid paper.
A triangle must satisfy both conditions below.
- All three vertices have integer coordinates.
- The area of the triangle is a positive integer.
Triangles built from the same dots in a different order count as different triangles. For example, the triangle built from , , and the triangle built from , , are two different triangles.
Input
The first line contains and , separated by a space ().
Output
Print the number of triangles that satisfy the conditions, modulo , on the first line.