Not so easy math

How to do this question with bitmasking?

Hi Anant
You need to use inclusion-exclusion principle mainly.
The same way you do it for questions like find number of numbers div by 2&3.
You find number of numbers div by 2+ number of numbers div by 3 - number of numbers div by 6.
Same way!
Bitmasking:
00 div by none
01 div by 2 only
10 div by 3 only
11 div by both 2 and 3

I hope you can relate.
Similarly in the question, you shall have mask with number of bits equal to number of prime numbers less than 20.

I didn’t get it completely. Can you please explain in detail.

if you have a,b,c,d,e as your prime numbers and you want to make combinations, that lets take abc, lets now take bde…
You can make all combinations using a mask.
Numbers from 0 to 31 (in binary form) would help denoting which one to take.

for eg.
10110 = take a,c,d
01111 = take b,c,d,e
00000 = take none
11111 = take a,b,c,d,e

in this way bitmasking can be used.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.