Gimme Gimme More
After a long and successful career as a competitive-programmer-turned-goose-farmer, you have more money than you know what to do with in your retirement. You decide to bestow some of your savings to your children. However, over time, due to your bad habits, you have also accumulated quite a few children.
Your favourite child is your youngest child, Maged Jr, but your other children will surely complain if you give him more money than them. Specifically, in order to keep your children happy, each child must receive a positive integer number of dollars, and each child must receive strictly more money than their immediate younger sibling.
Given you want to distribute dollars among
children, what is the most money you can give your youngest child while keeping your children happy?
If it is not possible to fulfil your children's demands, output -1 to let them know they are being unreasonable.
Input
The input consists of a single line containing two integers and
(
), representing the number of children, and the total amount of money you will pass down to them.
Output
Output the highest integer amount of money you can pay your youngest child while keeping all children happy according to the above property. Assume no children have exactly the same age (i.e. there are no twins, etc.). If it is impossible, output -1.
Examples
Input 1
1 7
Output 1
7
With only one child, the youngest is the only child and can receive all dollars.
Input 2
3 8
Output 2
1
There are three children. To give the youngest dollar, we can distribute
dollars from youngest to oldest, which preserves the property and takes
dollars. There are not enough dollars left over (
) to give the youngest child any more money; we can only make distributions such as
or
.
Input 3
4 5
Output 3
-1
It is impossible to give children positive integer amounts while preserving the property and having only
dollars. The minimum valid distribution would be
from youngest to oldest, which requires
dollars.
Input 4
7 50
Output 4
4
Input 5
1000 566500
Output 5
67
Comments