Official

A - Not coprime Editorial by evima


\(X_i\) and \(Y\) being not coprime means some integer \(d \geq 2\) divides both \(X_i\) and \(Y\). Here, we only need to consider minimal such \(d\), that is, a prime number.

Since there are \(15\) prime numbers not greater than \(50\), we can try all \(2^{15}\) subsets of those primes to find the minimum \(Y\). For each subset, we try to let \(Y\) be the product of the elements, and if there is \(X_i\) that is coprime with \(Y\), that choice of \(Y\) is invalid. The time complexity of this solution is \(\mathrm{O}(N2^{p(L)} \log L) (L := \max X)\), where \(p(i)\) is the number of primes not greater than \(i\).

posted:
last update: