Triangles

AtCoder
IDtokiomarine2020_f
Time4000ms
Memory256MB
Difficulty
In a two-dimensional plane, we have a rectangle $R$ whose vertices are $(0,0)$, $(W,0)$, $(0,H)$, and $(W,H)$, where $W$ and $H$ are positive integers. Here, find the number of triangles $\Delta$ in the plane that satisfy all of the following conditions: * Each vertex of $\Delta$ is a grid point, that is, has integer $x$\- and $y$\-coordinates. * $\Delta$ and $R$ shares no vertex. * Each vertex of $\Delta$ lies on the perimeter of $R$, and all the vertices belong to different sides of $R$. * $\Delta$ contains at most $K$ grid points strictly within itself (excluding its perimeter and vertices). ## Constraints * $1 \leq W \leq 10^5$ * $1 \leq H \leq 10^5$ * $0 \leq K \leq 10^5$ ## Input Input is given from Standard Input in the following format: $W$ $H$ $K$ [samples]
Samples
Input #1
2 3 1
Output #1
12

For example, the triangle with the vertices $(1,0)$, $(0,2)$, and $(2,2)$ contains just one grid point within itself and thus satisfies the condition.
Input #2
5 4 5
Output #2
132
Input #3
100 100 1000
Output #3
461316
API Response (JSON)
{
  "problem": {
    "name": "Triangles",
    "description": {
      "content": "In a two-dimensional plane, we have a rectangle $R$ whose vertices are $(0,0)$, $(W,0)$, $(0,H)$, and $(W,H)$, where $W$ and $H$ are positive integers. Here, find the number of triangles $\\Delta$ in t",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "tokiomarine2020_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In a two-dimensional plane, we have a rectangle $R$ whose vertices are $(0,0)$, $(W,0)$, $(0,H)$, and $(W,H)$, where $W$ and $H$ are positive integers. Here, find the number of triangles $\\Delta$ in t...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments