Need help in solution of NUMSET

This is link of problem NUMSET
Contest link
I write a solution and it is giving me WA :(.
now I am unable to find where I am wrong. I have seen the editorial but that is totally different.
this is my solution LINK
(sieve function in code has no use that was different approach that also gave me WA:( ).
My approach :-

  1. For every number I am finding count of numbers having GCD greater than 1(that are not co-prime).
  2. Now I am sorting the array according to count calculated in 1st step.
  3. I am taking all element from starting that are co-prime to all that i have taken for that I use set of all number that are not co-prime to added number.

Please let me know where I am going wrong or give me some test case in which my code is failing.
Thanks.

please help @kevinsogo @taran_1407 @vijju123

//