欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1195B.Sport Mafia
Sport Mafia
Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.
For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options:
- the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by ;
- the second option is to put candies in the box. In this case, Alya will put more candy, than she put in the previous time.
Thus, if the box is empty, then it can only use the second option.
For example, one possible sequence of Alya's actions look as follows:
- put one candy into the box;
- put two candies into the box;
- eat one candy from the box;
- eat one candy from the box;
- put three candies into the box;
- eat one candy from the box;
- put four candies into the box;
- eat one candy from the box;
- put five candies into the box;
This way she will perform actions, the number of candies at the end will be , while Alya will eat candies in total.
You know the total number of actions and the number of candies at the end . You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given and the answer always exists.
Please note, that during an action of the first option, Alya takes out and eats exactly one candy.
Input
The first line contains two integers and (; ) — the total number of moves and the number of candies in the box at the end.
It's guaranteed, that for the given and the answer exists.
Output
Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data.
Note
In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate candies.
In the second example the possible sequence of Alya's actions looks as follows:
- put candy,
- put candies,
- eat a candy,
- eat a candy,
- put candies,
- eat a candy,
- put candies,
- eat a candy,
- put candies.
This way, she will make exactly actions and in the end the box will contain candies. The answer is , since she ate candies in total.
Samples
1 1
0
9 11
4
5 0
3
3 2
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |