Tower Breakers Strike Back

In Tower Breakers Again, there are n towers of varying heights. A move consists of choosing a tower of height h and reducing it to a proper divisor of h (a divisor strictly less than h). The player who makes the last move wins. Determine the winner: return 1 if the first player wins, 2 if the second player wins.

The heights differ here, so the parity shortcut that works for identical towers no longer applies. Each tower is an independent impartial game whose Grundy number is the mex of the Grundy numbers of all its proper divisors.

A tower of height one is terminal with Grundy zero. Because the move graph over divisors is the divisor lattice, the Grundy number of a height equals the number of prime factors counted with multiplicity, so towers with the same prime-factor count share the same value. Combine the towers with XOR: a non-zero XOR is a first-player win and a zero XOR is a second-player win. Sieve the smallest prime factor up to the largest height to factor every tower quickly, then XOR the totals.

Examples
Input: [2,4]
Output: 1
Hints

Tower Breakers Strike Back

In Tower Breakers Again, there are `n` towers of varying heights. A move consists of choosing a tower of height `h` and reducing it to a **proper divisor** of `h` (a divisor strictly less than `h`). The player who makes the last move wins. Determine the winner: return 1 if the first player wins, 2 if the second player wins.