P3166 [CQOI2014] Counting Triangles

Description

Given an $N \times M$ grid, compute how many triangles have all three vertices at grid points. Note that the three points of a triangle must not be collinear.

Input Format

The input consists of one line containing two space-separated positive integers $M$ and $N$.

Output Format

Output a single positive integer, which is the number of such triangles.

Explanation/Hint

Constraints For all test points, $1 \le N, M \le 1000$. Translated by ChatGPT 5