Subset GCD

An array A having N elements. I want to check if there is any subset of A whose GCD is G.

For Ex:

G=2

A=[2 4 5 6 7 8]

Output:YES

Because gcd(2,4)=G

G= 3

A=[2 4 5 6 7 8]

Output:YES

Because gcd(2,6)=G

This is a question of an ongoing contest

Please wait for the contest to finish :confused: