Editorial for Bedao Regular Contest 13 - GCD


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: bedao

Dễ thấy, để ~\text{gcd}(a_i, x) > 1~, cần tồn tại một số nguyên dương ~d > 1~ là ước của cả ~a_i~ và ~x~. Tuy nhiên, vì ta đang muốn cực tiểu ~x~, ta chỉ cần quan tâm tới các ước nguyên tố của ~a_i~. Nói cách khác, ~x~ sẽ là tích của các số nguyên tố khác nhau.

Ta có ~15~ số nguyên tố nhỏ hơn hoặc bằng ~50~, vì vậy ta có thể thử toàn bộ ~2^{15}~ trường hợp của ~x~, và tìm ra số nhỏ nhất thỏa mãn đề bài.

Độ phức tạp: ~O(2^{15} \cdot n \cdot g)~, với ~g~ là chi phí của hàm ~\text{gcd}~.


Comments

Please read the guidelines before commenting.


There are no comments at the moment.