values of distinct positive integers. Arrange all of them in some order. Such an arrangement is a **divisor chain** if, for every two neighbouring numbers, one of them is divisible by the other.
Count how many different arrangements are divisor chains. The count can be huge, so return it modulo 10⁹ + 7.values=[4, 5, 20] → 2
[4, 20, 5] and [5, 20, 4] work: 20 is divisible by both 4 and 5, while 4 and 5 cannot stand next to each other.
values=[3, 9, 27] → 6
Any two of these numbers divide one another, so all 3! = 6 orderings work.
values=[2, 7] → 0
Neither 2 divides 7 nor 7 divides 2, so no ordering works.
values are distinctvalues=[4, 5, 20]
2
Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.