30 bit number with constraints

In reply to Rahulkumar:

can you try it without using $countones?

I got it using $countones.

Thanks!