CF1023B.Pair of Toys

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tanechka is shopping in the toy shop. There are exactly nn toys in the shop for sale, the cost of the ii-th toy is ii burles. She wants to choose two toys in such a way that their total cost is kk burles. How many ways to do that does she have?

Each toy appears in the shop exactly once. Pairs (a,b)(a, b) and (b,a)(b, a) are considered equal. Pairs (a,b)(a, b), where a=ba=b, are not allowed.

塔涅奇卡正在玩具店购物。店里恰好有 nn 个待售玩具,第 ii 个玩具的价格为 ii 卢布。她希望挑选两个玩具,使得它们的总价格恰好为 kk 卢布。她有多少种选择方式?

每个玩具在店里恰好出现一次。对 (a,b)(a, b) 和 (b,a)(b, a) 被视为同一种方案。不允许选择同一个玩具两次(即不允许 a=ba = b)。

输入格式

The first line of the input contains two integers nn, kk (1≤n,k≤10141 \le n, k \le 10^{14}) — the number of toys and the expected total cost of the pair of toys.

输入的第一行包含两个整数 nn、kk(1≤n,k≤10141 \le n, k \le 10^{14})—— 分别表示玩具的数量以及一对玩具的期望总成本。

输出格式

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 kk burles.

输出满足上述条件的玩具对的选择方案数。如果塔涅奇卡无法选择任何一对玩具,使其总价格恰好为 kk 卢布,则输出 0。

输入输出样例

  • 输入#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,41, 4) or the pair of toys (2,32, 3).

In the second example Tanechka can choose only the pair of toys (7,87, 8).

In the third example choosing any pair of toys will lead to the total cost less than 2020. So the answer is 0.

In the fourth example she can choose the following pairs: (1,1000000000000)(1, 1000000000000), (2,999999999999)(2, 999999999999), (3,999999999998)(3, 999999999998), ..., (500000000000,500000000001)(500000000000, 500000000001). The number of such pairs is exactly 500000000000500000000000.

在第一个例子中,塔涅奇卡可以选择玩具对 (1,4)(1, 4) 或玩具对 (2,3)(2, 3)。

在第二个例子中,塔涅奇卡只能选择玩具对 (7,8)(7, 8)。

在第三个例子中,任意选择一对玩具,其总花费均小于 2020。因此答案为 00。

在第四个例子中,她可以选择以下这些对:(1,1000000000000)(1, 1000000000000)、(2,999999999999)(2, 999999999999)、(3,999999999998)(3, 999999999998)、……、(500000000000,500000000001)(500000000000, 500000000001)。这样的对的数量恰好为 500000000000500000000000。

输入解题思路,AI测评打分。不知道怎么写?

首页