Codeforces Hello 2019 F. Alex and a TV Show

https://codeforces.com/contest/1097/problem/F

A[k] denote the number of multiples of k included in the multiset A. Then the following holds.

\[(A \cup B)[i]=A[i]+B[i]\]\[(A \times B)[i]=A[i] \times B[i]\]

Clearly, $A \cup B$. Conversely, $a$ and $b$ is both a multiple of $i$ if and only if $\gcd(a,b)$ が $i$ if a multiple of i.

Therefore, we can reduce the problem not condidering the number of k in the multiset, but considering the number of multiples of k in the multiset. After finding it, we should reduce the answer fitting the original condition. By inclusion exclusion

\[ A[k]-A[2k]-A[3k]-A[5k]+A[6k]-A[7k]+A[10k]-A[11k]-A[13k]+A[14k]+A[15k]+ \cdots \]

gives original values. Precisely,

\[ A[k] - \sum_{p}A[pk] + \sum_{p < q}A[pqk] - \sum_{p < q < r} A[pqrk] + \cdots \]

Since this problem only requires mod 2 values, we can use bitsets

https://codeforces.com/contest/1097/submission/47934091