rolls times and the results are written down in order. A sequence is allowed if:
- every two adjacent values are coprime (their greatest common divisor is 1);
- equal values are more than two positions apart: if positions i and j show the same value, then |i − j| > 2.
Count the distinct allowed sequences. The answer can be large, so return it modulo 10⁹ + 7.rolls=1 → 6
With a single roll, any of the six faces works.
rolls=2 → 22
Ordered pairs of distinct coprime faces work, such as (1, 6), (5, 4), (3, 2). Pairs like (2, 4), (3, 6) and pairs of equal faces do not. 22 pairs in total.
rolls=3 → 66
For example, (1, 2, 3) works but (1, 2, 1) does not: equal values are only one roll apart.
rolls=1
6
Run checks the first 3 tests in your browser. Submit checks all 23 tests on the server, hidden ones included.