A11870 | Pair of Toys
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
输出格式
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.
输入输出样例
输入 #1
8 5
输出 #1
2
输入 #2
8 15
输出 #2
1
输入 #3
7 20
输出 #3
0
输入 #4
1000000000000 1000000000001
输出 #4
500000000000
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted