Problem Statement
The elevators must satisfy the following conditions:
- For each floor, exactly one box stops at that floor.
- The distance between 2 boxes is an integer and never changes. More formally, for each pair of boxes (A,B), there must be some integer d such that box B always stops at the (x+d)-th floor when box A stops at the x-th floor. If the (x+d)-th floor doesn't exist, box A must not stop at the x-th floor.
Two elevators are different if the following is true. When the bottommost box is at the first floor, there exists an i such that a box is at the i-th floor in one elevator and no box is at the i-th floor in the other elevator. You are given two integers H and N. Return the number of possible elevators that have N boxes in a skyscraper of height H, modulo 1,000,000,007.
Definition
- Class:
- StrangeElevator
- Method:
- theCount
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int theCount(int H, int N)
- (be sure your method is public)
Constraints
- H will be between 1 and 1,000,000,000, inclusive.
- N will be between 1 and H, inclusive.
Examples
58
2
Returns: 2
The following two elevators are possible: When the lower box stops at the 1st, 3rd, ..., 57th floor, the upper box stops at the 2nd, 4th, ..., 58th floor, respectively. When the lower box stops at the 1st, 2nd, ..., 29th floor, the upper box stops at the 30th, 31st, ..., 58th floor, respectively.
1
1
Returns: 1
The only box always stops at the 1st floor.
9
3
Returns: 2
The following two elevators are possible: When the lowest box stops at the 1st, the 4th and the 7th floor, the middle box stops at the 2nd, the 5th and the 8th floor, and the topmost box stops at the 3rd, the 6th and the 9th floor, respectively. When the lowest box stops at the 1st, the 2nd and the 3rd floor, the middle box stops at the 4th, the 5th and the 6th floor, and the topmost box stops at the 7th, the 8th and the 9th floor, respectively.
120
12
Returns: 30
58585858
495
Returns: 0
1000000000
1000000000
Returns: 1
1000000000
100000
Returns: 46084626
1000000000
1
Returns: 1
182213016
143984807
Returns: 0
238647758
190736101
Returns: 0
555163223
250237128
Returns: 0
718317798
468980913
Returns: 0
124915584
94644450
Returns: 0
391483374
34506875
Returns: 0
221301889
28937254
Returns: 0
198250703
65436098
Returns: 0
609810568
192222420
Returns: 0
587687201
501458422
Returns: 0
735134400
1
Returns: 1
735134400
2
Returns: 1152
735134400
4
Returns: 72900
735134400
6
Returns: 121608
735134400
12
Returns: 2600520
735134400
24
Returns: 18151500
735134400
36
Returns: 17558970
735134400
48
Returns: 51573780
735134400
60
Returns: 34086480
735134400
120
Returns: 138797220
735134400
180
Returns: 126848370
735134400
240
Returns: 252235920
735134400
360
Returns: 337625220
735134400
720
Returns: 420874080
735134400
840
Returns: 359055300
735134400
1260
Returns: 311108580
735134400
1680
Returns: 433013040
735134400
2520
Returns: 551986500
735134400
5040
Returns: 469706280
735134400
7560
Returns: 225436100
735134400
10080
Returns: 182402316
735134400
15120
Returns: 136058760
735134400
20160
Returns: 24983364
735134400
25200
Returns: 184111080
735134400
27720
Returns: 563286180
735134400
45360
Returns: 0
735134400
50400
Returns: 49287108
735134400
55440
Returns: 328268040
735134400
83160
Returns: 149826020
735134400
110880
Returns: 85742724
735134400
166320
Returns: 60891960
735134400
221760
Returns: 7577976
735134400
277200
Returns: 80650680
735134400
332640
Returns: 10728708
735134400
498960
Returns: 0
735134400
554400
Returns: 13879440
735134400
665280
Returns: 599984
735134400
720720
Returns: 139926840
735134400
1081080
Returns: 60769220
735134400
1441440
Returns: 23331636
735134400
2162160
Returns: 15735600
735134400
2882880
Returns: 1208928
735134400
3603600
Returns: 20323320
735134400
4324320
Returns: 1618644
735134400
6486480
Returns: 0
735134400
7207200
Returns: 2028360
735134400
8648640
Returns: 44912
735134400
10810800
Returns: 1295400
735134400
14414400
Returns: 53928
735134400
17297280
Returns: 0
735134400
21621600
Returns: 67464
735134400
32432400
Returns: 0
735134400
36756720
Returns: 2077500
735134400
43243200
Returns: 672
735134400
61261200
Returns: 2600520
735134400
73513440
Returns: 101292
735134400
110270160
Returns: 0
735134400
122522400
Returns: 121608
735134400
147026880
Returns: 896
735134400
183783600
Returns: 72900
735134400
245044800
Returns: 1008
735134400
294053760
Returns: 0
735134400
367567200
Returns: 1152
735134400
551350800
Returns: 0
735134400
698377680
Returns: 0
735134400
735134400
Returns: 1
840
840
Returns: 1
61261200
120
Returns: 3558676
551350800
180
Returns: 71259384
498960
332640
Returns: 0
221760
12
Returns: 24450
665280
48
Returns: 363780
122522400
1260
Returns: 13685940
32432400
720
Returns: 4678080
14414400
840
Returns: 9883100
294053760
27720
Returns: 174730080
367567200
10080
Returns: 12831492
14414400
120
Returns: 5830940
277200
840
Returns: 62668
498960
10080
Returns: 0
2520
360
Returns: 24
1260
60
Returns: 96
294053760
45360
Returns: 0
21621600
120
Returns: 7723620
367567200
21621600
Returns: 576
61261200
12
Returns: 289704
122522400
110270160
Returns: 0
120
60
Returns: 12
665280
27720
Returns: 224100
551350800
665280
Returns: 0
60
36
Returns: 0
73513440
720720
Returns: 494100
698377680
720720
Returns: 494100
122522400
110270160
Returns: 0
83160
24
Returns: 5580
3603600
55440
Returns: 4740
999999999
999
Returns: 52
10
1
Returns: 1