Farmer Jane needs to be able to measure out corn to feed her cows, but all she has to help her is a primitive balance scale and a kilogram rock. With this rock she could use the balance scale to measure out kg of corn, but she often needs to measure out smaller quantities. She figures out that if she breaks the rock into three pieces, where two of them are kg and the third is kg, then she can measure out all integer quantities of corn from to , as shown below.
Farmer Jane is happy now, but the situation gets her thinking. She knows she could have broken the rock into , , and kg pieces and this would also have worked. But things are not so simple for other numbers. For example, there are ways to break a kg rock into integer pieces but only of them let you measure all integer weights from to . She wonders if there could be some kind of algorithm to determine how many combinations work for a given size of rock and a given number of pieces…
The input contains test cases.
Each test case consists of two integers ( and ) on a single line separated by a space. The integer gives the number of pieces to break the rock into and the integer gives the original size of the rock. For all test cases, .
For the first test cases and for the next test cases .
Your job is to output a single line for each test case indicating the number of ways you can break up the rock into integer-sized pieces so that all possible integer weights from to can be measured on a balance scale.
Sample Input
3 6
4 12
4 30
5 40
5 5
6 25
7 55
8 65
9 75
10 85
Sample Output
2
9
5
137
1
154
5749
28051
121108
474402
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org
Comments