How many numbers between 1 and 1,000 (both inclusive) are divisible by at least one of the prime between 1 to 50? How can I find this?

42 Views Asked by At

I was trying to solve a compettive programming problem in which constraints are so high so I want to deduce a formula for it so that i could do it for other ranges as well.

1

There are 1 best solutions below

0
On BEST ANSWER

As $50^2>1000$, the only numbers in this range that aren't divisible are $1$ and the primes between $50$ and $1000$. So the answer is $$1+\pi(1000)-\pi(50)=1+168-15=154.$$