304089: CF785C. Anton and Fairy Tale
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Anton and Fairy Tale
题意翻译
有一个仓库,容量为 $n$,刚开始有 $n$ 粒谷,每天会依次发生以下两件事: 1. 带来 $m$ 粒谷,如果超过容量 $n$,就只会有 $n$ 粒谷。 2. 第一天有一只鸟,第二天有两只鸟,以此类推,每天一只鸟都会吃一粒谷。 求:第几天结束后,仓库一粒谷都没有了。题目描述
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!输入输出格式
输入格式
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 one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.
输入输出样例
输入样例 #1
5 2
输出样例 #1
4
输入样例 #2
8 1
输出样例 #2
5