My approach-Calculated LCM of all numbers and tried to find numbers upto that lcm which are not divisible by it and accordingly finding uptil n as a cycle is repeated and remaining are separately counted.

My code-code (I have added comments where solution starts and ends)

My searches on google-Checked it on github as people have posted solutions there also checked a online forum where this question was discussed. By looking them they have checked j uptil 1<<m and checking for all array values of 1<<i (where i is the index of array) that if j&(1<<i) !=0 execute it.

My question-Why the above process was done. What does this -j&(1<<i) !=0 achieve. Any other way would also be appreciated. Please guys if anybody could explain this would be highly helpful

Say F(X) → Number multiples of X which are less than N. It’s trivial to see that F(X)=\displaystyle \frac{N}{X} A_i → Set of all subsequences of size i. So if you apply exclusion-inclusion the problem boils down to finding the following summation.