can anyone explain me logic for solving this problem not the code only logic part.as the editorial is very confusing

Where can I find the editorial? Thanks
[Edit] Found it: FUZZYLIN - Editorial

1 Like

The editorial starts by converting the problem description to some form of mathematical statement.

Do you understand and agree that \{b_1, b_2, ..., b_n\} generates X if and only if gcd(b_1,b_2,...,b_n) divides X?

yes i have understood that part thats because of diophantine equation