Unable to get to the solution

Can you please , tell why this solution is wrong

please provide with the solution
thanks

Hey @YatharthVardan
Why its wrong: Say you have the array of only first 2 prime numbers. {2, 3}
Number of numbers divisible by 2 be int d2 = N / 2;
Number of numbers divisible by 3 be int d3 = N / 3;

But the answer is not equal to d2 + d3 as now there is some overlapping.
Because now numbers between 1 and N that are divisible by 6 are counted twice.
So we need to subtract those numbers. So,
Number of numbers divisible by 6 be int d6 = N / 6;

So answer for this problem will be d2 + d3 - d6 (int ans = d2 + d3 - d6;).
This was just for 2 and 3, you need to do this for the whole array of {2, 3, 5, 7, 11, 13, 17, 19}.

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.