English · Original
Chinese · Translation
Formal · Original
Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$\-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k$ burles. How many ways to do that does she have?
Each toy appears in the shop exactly once. Pairs $(a, b)$ and $(b, a)$ are considered equal. Pairs $(a, b)$, where $a=b$, are not allowed.
## Input
The first line of the input contains two integers $n$, $k$ ($1 \le n, k \le 10^{14}$) — the number of toys and the expected total cost of the pair of toys.
## Output
Print the number of ways to choose the pair of toys satisfying the condition above. Print _0_, if Tanechka can choose no pair of toys in such a way that their total cost is $k$ burles.
[samples]
## Note
In the first example Tanechka can choose the pair of toys ($1, 4$) or the pair of toys ($2, 3$).
In the second example Tanechka can choose only the pair of toys ($7, 8$).
In the third example choosing any pair of toys will lead to the total cost less than $20$. So the answer is _0_.
In the fourth example she can choose the following pairs: $(1, 1000000000000)$, $(2, 999999999999)$, $(3, 999999999998)$, ..., $(500000000000, 500000000001)$. The number of such pairs is exactly $500000000000$.
Tanechka 在玩具店购物。店里恰好有 $n$ 个玩具待售,第 $i$ 个玩具的价格为 $i$ 布尔。她希望选择两个玩具,使得它们的总价格为 $k$ 布尔。有多少种选择方式?
每个玩具在店里仅出现一次。对 $(a, b)$ 和 $(b, a)$ 视为相同。不允许选择 $a = b$ 的对 $(a, b)$。
输入的第一行包含两个整数 $n$, $k$ ($1 lt.eq n, k lt.eq 10^(14)$) —— 玩具的数量和期望的玩具对总价格。
请输出满足上述条件的玩具对的选择方式数量。如果 Tanechka 无法选择任何一对玩具使其总价格为 $k$ 布尔,请输出 _0_。
在第一个例子中,Tanechka 可以选择玩具对 $(1, 4)$ 或 $(2, 3)$。
在第二个例子中,Tanechka 只能选择玩具对 $(7, 8)$。
在第三个例子中,选择任意一对玩具都会导致总价格小于 $20$。因此答案为 _0_。
在第四个例子中,她可以选择以下对:$(1, 1000000000000)$, $(2, 999999999999)$, $(3, 999999999998)$, ..., $(500000000000, 500000000001)$。这样的对的数量恰好为 $500000000000$。
## Input
输入的第一行包含两个整数 $n$, $k$ ($1 lt.eq n, k lt.eq 10^(14)$) —— 玩具的数量和期望的玩具对总价格。
## Output
请输出满足上述条件的玩具对的选择方式数量。如果 Tanechka 无法选择任何一对玩具使其总价格为 $k$ 布尔,请输出 _0_。
[samples]
## Note
在第一个例子中,Tanechka 可以选择玩具对 $(1, 4)$ 或 $(2, 3)$。在第二个例子中,Tanechka 只能选择玩具对 $(7, 8)$。在第三个例子中,选择任意一对玩具都会导致总价格小于 $20$。因此答案为 _0_。在第四个例子中,她可以选择以下对:$(1, 1000000000000)$, $(2, 999999999999)$, $(3, 999999999998)$, ..., $(500000000000, 500000000001)$。这样的对的数量恰好为 $500000000000$。
**Definitions**
Let $ n, k \in \mathbb{Z}^+ $ with $ 1 \leq n, k \leq 10^{14} $.
Let $ T = \{1, 2, \dots, n\} $ be the set of toy costs.
Let $ P = \{ \{a, b\} \subseteq T \mid a < b \text{ and } a + b = k \} $ be the set of valid unordered pairs.
**Constraints**
1. $ a, b \in T $
2. $ a \neq b $
3. $ a + b = k $
4. $ a < b $ (to enforce unordered pairs without duplication)
**Objective**
Compute $ |P| $, the number of unordered pairs $ \{a, b\} $ such that $ a + b = k $, $ 1 \leq a < b \leq n $.
---
**Formal Expression:**
$$
|P| = \left| \left\{ a \in \mathbb{Z} \mid 1 \leq a < \frac{k}{2},\ a \leq n,\ k - a \leq n,\ k - a > a \right\} \right|
$$
Equivalently, define the range of valid $ a $:
Let $ a_{\min} = \max(1, k - n) $,
Let $ a_{\max} = \min\left( \left\lfloor \frac{k-1}{2} \right\rfloor, n \right) $.
Then:
$$
|P| = \max\left(0,\ a_{\max} - a_{\min} + 1 \right)
$$
API Response (JSON)
{
"problem": {
"name": "B. Pair of Toys",
"description": {
"content": "Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$\\-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 1000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF1023B"
},
"statements": [
{
"statement_type": "Markdown",
"content": "Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$\\-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "Tanechka 在玩具店购物。店里恰好有 $n$ 个玩具待售,第 $i$ 个玩具的价格为 $i$ 布尔。她希望选择两个玩具,使得它们的总价格为 $k$ 布尔。有多少种选择方式?\n\n每个玩具在店里仅出现一次。对 $(a, b)$ 和 $(b, a)$ 视为相同。不允许选择 $a = b$ 的对 $(a, b)$。\n\n输入的第一行包含两个整数 $n$, $k$ ($1 lt.eq n, k lt.e...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ n, k \\in \\mathbb{Z}^+ $ with $ 1 \\leq n, k \\leq 10^{14} $. \nLet $ T = \\{1, 2, \\dots, n\\} $ be the set of toy costs. \nLet $ P = \\{ \\{a, b\\} \\subseteq T \\mid a < b \\text{ and }...",
"is_translate": false,
"language": "Formal"
}
]
}