Triangular Relationship

AtCoder
IDarc102_a
Time2000ms
Memory256MB
Difficulty
You are given integers $N$ and $K$. Find the number of triples $(a,b,c)$ of positive integers not greater than $N$ such that $a+b,b+c$ and $c+a$ are all multiples of $K$. The order of $a,b,c$ does matter, and some of them can be the same. ## Constraints * $1 \leq N,K \leq 2\times 10^5$ * $N$ and $K$ are integers. ## Input Input is given from Standard Input in the following format: $N$ $K$ [samples]
Samples
Input #1
3 2
Output #1
9

$(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1)$ and $(3,3,3)$ satisfy the condition.
Input #2
5 3
Output #2
1
Input #3
31415 9265
Output #3
27
Input #4
35897 932
Output #4
114191
API Response (JSON)
{
  "problem": {
    "name": "Triangular Relationship",
    "description": {
      "content": "You are given integers $N$ and $K$. Find the number of triples $(a,b,c)$ of positive integers not greater than $N$ such that $a+b,b+c$ and $c+a$ are all multiples of $K$. The order of $a,b,c$ does mat",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc102_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given integers $N$ and $K$. Find the number of triples $(a,b,c)$ of positive integers not greater than $N$ such that $a+b,b+c$ and $c+a$ are all multiples of $K$. The order of $a,b,c$ does mat...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments