Problem Statement
- Each character of the string is either a '0' or a '1'.
- There are no two consecutive '1's in the string.
- Let x be the number of '0's in s.
- Let y be the number of '1's in s.
- The weight of s is (x^a) * (y^b).
Definition
- Class:
- FibonacciStringSum
- Method:
- get
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int get(int n, int a, int b)
- (be sure your method is public)
Constraints
- n will be between 1 and 1,000,000,000, inclusive.
- a will be between 0 and 25, inclusive.
- b will be between 0 and 25, inclusive.
Examples
1000000000
25
25
Returns: 572727199
536870911
25
25
Returns: 449528631
158260522
6
23
Returns: 640706797
745344240
18
9
Returns: 894154618
118642159
2
10
Returns: 36301786
805214284
22
18
Returns: 179758717
442238608
14
3
Returns: 764112312
216618928
17
24
Returns: 802728062
115516813
19
12
Returns: 903248205
909788622
17
1
Returns: 711005535
131071
5
17
Returns: 26802153
1
13
20
Returns: 0
131071
25
23
Returns: 956099469
536870911
24
23
Returns: 916012684
32767
21
24
Returns: 337339515
536870911
18
24
Returns: 365331523
536870911
21
25
Returns: 529664622
536870911
21
19
Returns: 848699368
536870911
20
25
Returns: 445715445
123
0
1
Returns: 52782618
46543213
1
0
Returns: 219561263
548792
0
0
Returns: 944243269
213978
10
10
Returns: 794939670
321987546
1
1
Returns: 957907653
268435455
23
23
Returns: 893602578
536870911
25
25
Returns: 449528631
268435455
22
23
Returns: 467682482
3
0
0
Returns: 5
We have five Fibonacci strings of length 3: "000", "001", "010", "100", "101". As a=b=0, the weight of each Fibonacci string is 1. Hence, the sum of weights of our five strings is 5.
3
0
1
Returns: 5
With a=0 and b=1, the weight of a string is the number of ones it contains. The correct return value is w("000") + w("001") + w("010") + w("100") + w("101") = 0 + 1 + 1 + 1 + 2 = 5.
10
10
10
Returns: 518500021
Watch out for integer overflow.
5000
20
20
Returns: 880245669
1
0
0
Returns: 2
1
0
1
Returns: 1
1
1
0
Returns: 1
1
1
1
Returns: 0