301520: CF287B. Pipeline

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Pipeline

题意翻译

题目描述 B城市自来水厂有n个客户需要供水,现在只有一条主管道通往这n个客户。但每个客户都希望单独需要一条管道进自己家里供水,于是只能用分离器将一管道变为多管道。 现在自来水厂有k-1个分离器,型号分别是2-out,3-out,…, k-out,其中,i-out代表这个分离器可以接入一个管道,产生出i个管道(即将1管道变为i管道)。自来水厂想知道,最少用几个分离器,可以满足n个客户的需求,输出最少数量;无法满足客户需求,则输出-1。 例如n=4,k=3,那么需要2-out和3-out的分离器才能使得一个管道变为4个管道,至少需要2个。 另外n=8, k=4时,最多只能变成7个管道,无法满足客户需求,输出-1。 输入 输入n, k 输出 输出最少数量,无法满足输出-1。

题目描述

Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly $ n $ houses in Ultimate Thule, Vova wants the city to have exactly $ n $ pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters. A splitter is a construction that consists of one input (it can be connected to a water pipe) and $ x $ output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF287B/d347ad4c15760876dd4efdb4df653ce9dd1bfe47.png)The figure shows a $ 4 $ -output splitterVova has one splitter of each kind: with $ 2 $ , $ 3 $ , $ 4 $ , ..., $ k $ outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible. Vova needs the pipeline to have exactly $ n $ pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.

输入输出格式

输入格式


The first line contains two space-separated integers $ n $ and $ k $ ( $ 1<=n<=10^{18} $ , $ 2<=k<=10^{9} $ ). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输出格式


Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.

输入输出样例

输入样例 #1

4 3

输出样例 #1

2

输入样例 #2

5 5

输出样例 #2

1

输入样例 #3

8 4

输出样例 #3

-1

Input

题意翻译

题目描述 B城市自来水厂有n个客户需要供水,现在只有一条主管道通往这n个客户。但每个客户都希望单独需要一条管道进自己家里供水,于是只能用分离器将一管道变为多管道。 现在自来水厂有k-1个分离器,型号分别是2-out,3-out,…, k-out,其中,i-out代表这个分离器可以接入一个管道,产生出i个管道(即将1管道变为i管道)。自来水厂想知道,最少用几个分离器,可以满足n个客户的需求,输出最少数量;无法满足客户需求,则输出-1。 例如n=4,k=3,那么需要2-out和3-out的分离器才能使得一个管道变为4个管道,至少需要2个。 另外n=8, k=4时,最多只能变成7个管道,无法满足客户需求,输出-1。 输入 输入n, k 输出 输出最少数量,无法满足输出-1。

加入题单

算法标签: