beads. All the beads are strung into a chain in some order. A chain is pretty if the numbers on every two neighbouring beads add up to a perfect square.
Return the number of different pretty chains. Two chains differ if some position holds different numbers in them; beads with the same number are indistinguishable.
A chain of a single bead is always pretty.beads=[3, 6, 13] → 2
The chains [6, 3, 13] and [13, 3, 6] work: 6 + 3 = 9 and 3 + 13 = 16.
beads=[8, 8, 1] → 3
8 + 8 = 16 and 8 + 1 = 9, so [1, 8, 8], [8, 1, 8] and [8, 8, 1] all work. Swapping the two equal 8s does not make a new chain.
beads=[2, 5] → 0
beads) ≤ 12beads[i] ≤ 10⁹beads=[3, 6, 13]
2
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.