Find the expected value of the number of segments in a string of length A in a language having alphabet size B.
A segment in defined as maximum contiguous substring containing the same character. E.g. In string 10011, the segments are 1, 00 and 11. The number of segments will be 3.
1 <= A,B <= 109
The first argument contains an integer A, denoting the length of the string.
The second argument contains an integer B, denoting the alphabet size.
Return the expected value of the number of segments. This can be represented in the form of x/y. Return x.y-1 (mod 109 + 7 ).
A = 1 B = 2
A = 2 B = 2
The length is 1. So there will only be 1 segment.
There are 4 cases-
00-1 segment 01-2 segments 10-2 segments 11-1 segment
Hence, the expected number of segments is 6/4.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.