CF785C.Anton and Fairy Tale

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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!

安东喜欢听童话故事,尤其是当安东最好的朋友达尼克给他讲故事的时候。此刻,达尼克正在给安东讲一个童话故事:

“从前,有一位皇帝。他非常富有,拥有大量谷物。有一天,他下令建造一座巨大的谷仓,用来存放他所有的谷物。最优秀的工匠们连续三天三夜建造这座谷仓。但他们疏忽了,谷仓上留下了一个小洞,每天麻雀都会从这个洞飞进来。一只麻雀飞进来,叼走一粒谷物,然后飞走了……”

更形式化地,童话中发生的过程如下:在第一天开始时,容量为 nn 粒谷物的谷仓是满的。随后,每一天(从第一天开始)都会发生以下事件:

  • 向谷仓中运入 mm 粒谷物。如果 mm 粒谷物无法全部装入谷仓,则谷仓被装满,多余无法装入的谷物被运回(本题中,我们可以假设这些无法装入谷仓的谷物不计入考虑)。
  • 麻雀飞来吃谷物。第 ii 天会有 ii 只麻雀飞来,即第一天有 1 只麻雀,第二天有 2 只麻雀,依此类推。每只麻雀吃 1 粒谷物;如果谷仓已空,则麻雀什么也吃不到。

安东已经听腻了达尼克逐一描述每只麻雀从谷仓中啄食谷物的过程。安东不知道这个童话故事何时结束,因此他请你帮他确定:谷仓首次变空是在第几天结束时? 请帮助安东编写一个程序,计算出这一天的序号!

输入格式

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018) — the capacity of the barn and the number of grains that are brought every day.

输入仅包含一行,有两个整数 nn 和 mm(1 ≤ n, m ≤ 10181 ≤ n, m ≤ 10^{18})——分别表示谷仓的容量以及每天运来的谷物数量。

输出格式

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 开始编号。

输入输出样例

  • 输入#1

    5 2

    输出#1

    4
  • 输入#2

    8 1

    输出#2

    5

说明/提示

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.

在第一个样例中,谷仓的容量为 5 粒谷物,每天运来 2 粒谷物。过程如下:

  • 第一天开始时,运来谷物。此时谷仓已满,因此不发生其他变化。
  • 第一天结束时,1 只麻雀飞来并吃掉 1 粒谷物,剩余 5 − 1 = 45 - 1 = 4 粒谷物。
  • 第二天开始时,运来 2 粒谷物。谷仓再次装满,其中 1 粒谷物无法装入。
  • 第二天结束时,2 只麻雀飞来并吃掉谷物,剩余 5 − 2 = 35 - 2 = 3 粒谷物。
  • 第三天开始时,运来 2 粒谷物。谷仓再次装满。
  • 第三天结束时,3 只麻雀飞来并吃掉谷物,剩余 5 − 3 = 25 - 3 = 2 粒谷物。
  • 第四天开始时,再次运来谷物,剩余 2 + 2 = 42 + 2 = 4 粒谷物。
  • 第四天结束时,4 只麻雀飞来并吃掉谷物,剩余 4 − 4 = 04 - 4 = 0 粒谷物。谷仓变为空。

因此答案为 4,因为到第四天结束时谷仓变为空。

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

首页