[Math] Number of integers not divisible by $p$ and $q$

divisibilitymodular arithmeticnumber-systems

Here's a part of question from Siklos' "Advanced Problems in Core Mathematics":

How many integers greater than or equal to zero and less than 1000 are not divisible by 2 or 5? What is the average value of these integers?

The solution is enclosed in the booklet (Question 11.), and might be worth taking a look at before attempting my actual question which is posed by Siklos at the end of his solution to the aforementioned question, but left to the reader to figure out.

The question is about what the general result is, i.e.:

How many integers greater than or equal to zero and less than $(pq)^3$ are not divisible by $p$ or $q$? What is the average value of these integers?

I had a look at a couple of cases, and some patterns do emerge, but I had no luck forming a general conjecture.

Added: As the first part of the question has been answered by Zev Chonoles, I thought I'll update the question with a interesting pattern that emerges when dealing with the second part, i.e. finding the average value of the integers.

First off, note that the number of integers becomes an arithmetic progression if we think in blocks of $pq$ numbers. So for $p=2$ and $q=5$ the number of integers not divisible by 2 or 5 is $4,8,12,16,\ldots$ for integers greater than or equal to zero and less than $10,20,30,40,\ldots$.

Then if we consider the integers in each such block, we notice that they can be paired to give the same sum, equal to the block size (a multiple of $pq$). Taking yet again $p=2$ and $q=5$ as an example, given $S_x=\{0,1,\ldots,x-1\}$:

$$\{n\in S_{20}: 2\nmid n\text{ or }5\nmid n\}=\{\color{red}{1},\color{green}{3},\color{blue}{7},\color{orange}{9},\color{orange}{11},\color{blue}{13},\color{green}{17},\color{red}{19}\}$$

Now I wonder, how can we explain this pattern and how can we use it to answer the second part of the question?

Best Answer

Here's an answer to your first question (I assume $p$ and $q$ are prime numbers, though the following argument works just as well for any relatively prime integers $p$ and $q$): let $S=\{0,1,\ldots,(pq)^3-1\}$. Then by the inclusion-exclusion principle,

$$\#\{n\in S: p\nmid n\text{ and }q\nmid n\}=$$ $$\#S\;\;-\;\;\#\{n\in S: p\mid n\}\;\;-\;\;\#\{n\in S: q\mid n\}\;\; + \;\;\#\{n\in S: p\mid n\text{ and }q\mid n\}$$

which is just $$p^3q^3-p^2q^3-p^3q^2+p^2q^2=p^2q^2(pq-q-p+1)=p^2q^2(p-1)(q-1).$$


TonyK has answered the second question (be sure to vote up his answer too!):

Write out the numbers from 1 (not 0!) to $(pq)^3 - 1$ that are not divisible by $p$ or $q$. Now write the same sequence backwards underneath the first one. Each column will sum to $(pq)^3$, because $n$ is divisible by $p$ or $q$ if and only if $(pq)^3 - n$ is. So the average value is $(pq)^3/2$.

Related Question