Here is a wheel with 10 numbers:
Suppose that the wheel begins in the position above. We are given an integer N in the range 0 ≤ N ≤ 100. We will spin the wheel three times. On each of the three spins, the wheel will rotate counterclockwise by a number of positions randomly chosen (uniformly) from the integers 0 .. N. For example, if N = 3, then on each spin there is
- a 1/4 chance that it will not rotate
- a 1/4 chance that it will rotate by 1 position
- a 1/4 chance that it will rotate by 2 positions
- a 1/4 chance that it will rotate by 3 positions
What is the exact probability that after the 3 spins the wheel will end up in the same position in which it started, i.e. pointing to number 1?
Write a program that can answer this question. The program should read the integer N on a single line of standard input, and write the answer as a fraction in reduced form.
Sample input:
3
Output:
1/64
Explanation: When N = 3, the wheel cannot possibly make a complete rotation in 3 spins. So it will end up at the starting position only if it never moves. On each spin, the probability that it won't move is 1/4, so the probability that it never moves is
(1/4)(1/4)(1/4) = 1/64
Sample input #2:
9
Output:
1/10
Explanation:
When N = 9, the wheel will be in a (uniformly) random position after every spin. Therefore after 3 spins (or any number of spins, for that matter), the probability that it will be pointing to the number 1 is 1/10.
Sample input #3:
7
Output:
13/128
Hint:
Consider every possible sequence of 3 spins, and count how many of them end at the starting position. The probability of ending at the starting position is this count divided by the number of possible sequences.