this is link to my solution , please check
For the above question some of the test cases are wrong!
@vishaaltiwari1999 hey test cases are okay. You are not using correct approach, first thing the Number need not to be a prime, it should not have factors as the numbers listed in question.
To solve this first find CB numbers if length 1 then length 2 and so on, also maintain a visited array so as to not use any number twice.
Code for refernce.
If this solves your doubt mark it as resolved.