Codeforces Round 404 (Div. 2)
C
Anton and Fairy Tale
Codeforces
1600
原题
← BD →
翻译中…

Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:

翻译中…

"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..."

翻译中…

More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of $*n*$ grains was full. Then, every day (starting with the first day) the following happens:

翻译中…
  • $*m*$ grains are brought to the barn. If $*m*$ grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account).
  • Sparrows come and eat grain. In the $*i*$-th day $*i*$ sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing.
翻译中…

Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!

翻译中…

Input

翻译中…

The only line of the input contains two integers $*n*$ and $*m*$ $(1 ≤ *n*, *m* ≤ 10^{18})$ — the capacity of the barn and the number of grains that are brought every day.

翻译中…

Output

翻译中…

Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.

翻译中…

Note

翻译中…

In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens:

翻译中…
  • At the beginning of the first day grain is brought to the barn. It's full, so nothing happens.
  • At the end of the first day one sparrow comes and eats one grain, so $5 - 1 = 4$ grains remain.
  • At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it.
  • At the end of the second day two sparrows come. $5 - 2 = 3$ grains remain.
  • At the beginning of the third day two grains are brought. The barn becomes full again.
  • At the end of the third day three sparrows come and eat grain. $5 - 3 = 2$ grains remain.
  • At the beginning of the fourth day grain is brought again. $2 + 2 = 4$ grains remain.
  • At the end of the fourth day four sparrows come and eat grain. $4 - 4 = 0$ grains remain. The barn is empty.
翻译中…

So the answer is $4$, because by the end of the fourth day the barn becomes empty.

翻译中…

样例

Input #1
5 2
Output #1
4
InputCopy OutputCopy
Input #2
8 1
Output #2
5
InputCopy OutputCopy
题目信息
题号
785C
时间限制
1 s
内存限制
256 MB
标签
二分
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。