Count stable rune fusions
Your task
A crafting system fuses two runes into one. Every rune carries a positive integer charge, and a fusion is stable when the product of the two charges is a perfect square, the square of some whole number. Runes at two different positions may fuse even when their charges are equal, and no rune fuses with itself. Charges reach a billion, so the product of two of them lands outside the range where a double counts exactly. Given the charges in catalogue order, return a list where position i holds how many other positions hold a rune that fuses stably with the rune at position i.
Examples
fusion_partner_counts(charges: list[int]) -> list[int]Example 1
Input
fusion_partner_counts([2, 8, 3])Output
[1, 1, 0]Example 2
Input
fusion_partner_counts([5, 5, 20])Output
[2, 2, 2]Example 3
Input
fusion_partner_counts([1, 4, 9, 7])Output
[2, 2, 2, 0]