Ai + Bj + Ck = X (1 <= i, j, k <= N)

AtCoder
IDabc315_g
Time2000ms
Memory256MB
Difficulty
You are given integers $N,A,B,C,X$. Find the number of triples of integers $(i,j,k)$ that satisfy all of the following conditions. * $1 \le i,j,k \le N$ * $Ai+Bj+Ck=X$ ## Constraints * All input values are integers. * $1 \le N \le 10^6$ * $1 \le A,B,C \le 10^9$ * $1 \le X \le 3 \times 10^{15}$ ## Input The input is given from Standard Input in the following format: $N$ $A$ $B$ $C$ $X$ [samples]
Samples
Input #1
5 3 1 5 15
Output #1
3

The following three triples satisfy the conditions.

*   $(1,2,2)$ : $3 \times 1 + 1 \times 2 + 5 \times 2 = 15$
*   $(2,4,1)$ : $3 \times 2 + 1 \times 4 + 5 \times 1 = 15$
*   $(3,1,1)$ : $3 \times 3 + 1 \times 1 + 5 \times 1 = 15$
Input #2
1 1 1 1 1
Output #2
0
Input #3
100000 31415 92653 58979 1000000000
Output #3
2896
API Response (JSON)
{
  "problem": {
    "name": "Ai + Bj + Ck = X (1 <= i, j, k <= N)",
    "description": {
      "content": "You are given integers $N,A,B,C,X$. Find the number of triples of integers $(i,j,k)$ that satisfy all of the following conditions. *   $1 \\le i,j,k \\le N$ *   $Ai+Bj+Ck=X$",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc315_g"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given integers $N,A,B,C,X$. Find the number of triples of integers $(i,j,k)$ that satisfy all of the following conditions.\n\n*   $1 \\le i,j,k \\le N$\n*   $Ai+Bj+Ck=X$\n\n## Constraints\n\n*   All in...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments