# Find sum of numbers from $1-100$ which are not divisible by $3$ and$7$

Question explains everything but I'm stuck at a certain part. I found:

• sum of numbers from $1-100$
• sum of numbers from $1-100$ divisible by $3$
• sum of numbers from $1-100$ divisible by $7$

Then subtracted first sum by last $2$ sums as mentioned above but there are certain numbers that appear in both tables. Ex: $21$ in $3$ and $7$, next is $42$, $63$ and $84$ My question is how to find these numbers ? I can't check every number from $1-100$. Is there any formula for this ?

• See here and do the same for $(3,7)$ instead of $(3,5)$. – Dietrich Burde Jan 2 '17 at 16:36
• Do you mean "$3$ and $7$" or "$3$ or $7$" ? – Yves Daoust Jan 2 '17 at 17:04
• Hint: the numbers that appear in both tables are multiples of $21$. – Yves Daoust Jan 2 '17 at 17:05

If you are familiar with unions and intersections of sets , then it is not a difficult problem.

Your answer should be: Total sum-(sum of multiple of $3 +$ sum of multiple of $7 -$ sum of multiple of $21)$

Since $21$ is LCM of $3$ & $7$

• The word you used "LCM" made my concept clear. Thank you – Suleman Jan 2 '17 at 18:51
• I'm not sure whether the analogy with sets is helpful here, since sets don't have a notion of "negative membership", so the sum of the elements in $\mathbb{N}_{100} \setminus (3\,\mathbb{N}_{100} \cup 7\,\mathbb{N}_{100})$ would be exactly right, since the multiples of $21$ don't need to be "added back in". – Joshua Taylor Jan 2 '17 at 20:56
• @JoshuaTaylor If you define the "summation measure" on $\mathbb{N}$ to be $\mu(\{x\}) = x$, then invoking the Inclusion-Exclusion principle shows this. – Henricus V. Jan 3 '17 at 0:31

Number of multiples of $3$ between $1$ & $100$ = $[\frac{100}{3}]$ = $33$,

Number of multiples of $7$ between $1$ & $100 =$ $[\frac{100}{7}]$ = $14$,

Number of multiples of $21$ between $1$ & $100$ = $[\frac{100}{21}]$ = $4$,

Where $[x]$ is the box function.

Sum of first 100 terms excluding terms divisible by $3$ and $7$:

$$S = \sum_{i=1}^{100} i - 3\sum_{i=1}^{33} i - 7\sum_{i=1}^{14} i + 21\sum_{i=1}^4 i.$$

Apply the formula for $\sum_{i=1}^n i$ and take it from here.

• Fair and easy. +1 – Vidyanshu Mishra Jan 3 '17 at 4:35

Sum of numbers divisible by $3=1683$

Sum of numbers divisible by $7=735$

Sum of numbers divisible by $21=210$

We need the sum of divisor of $21$ since if we subtract only by the Sum of divisor of $3$ and Sum of divisor of $7$ then the numbers those are divisible by both $3$ & $7$ means divisible by $21$ will be subtracted twice but we need to subtract it only once.

$\therefore$
The sum of numbers not divisible by $3$ & $7=$ Sum of first $100$ natural numbers $-$ Sum of divisor of $3-$ Sum of divisor of $7+$ Sum of divisor of $21$

$=5050-1683-735+210$

$=2842$

• Shouldn't it be 5050 instead of 10100? – Nilabro Saha Jan 2 '17 at 18:31
• I beg your pardon – Harsh Kumar Jan 2 '17 at 18:33

Its simple find the sum of terms divisible by 21. And add this sum.

Sum of first 100 terms excluding terms divisible by 3 and 7 = Sum of first 100 terms - Sum of terms divisible by 3 - Sum of terms divisible by 21 + Sum of terms divisible by 21.

Because when you are subtracting the sum of terms divisible by 3 and sum of terms divisible by 7 few terms which are divisible by both subtracted twice. So add sum of terms divisible by 21.

Numbers divisible by 3 are 3, 6, 9, ...., 99.

Numbers divisible by 7 are 7, 14, 21, 28, ...., 98.

Numbers divisible by 21 are 21, 42, 63, 84.

Now we have sum of first 100 numbers not divisible by 3 and 7 is

(1 + 2 + 3 + .... + 100) - (3 + 6 + 9 + .... + 99) - (7 + 14 + 21 + .... + 98) + (21 + 42 + 63 + 84)

= (1 + 2 + 3 + .... + 100) - 3(1 + 2 + 3 + .... + 33) - 7(1 + 2 + 3 + .... + 14) + 21(1 + 2 + 3 + 4)

Using formula -

$$\sum_{k = 1}^{n} k = \tfrac{1}{2} (n)(n+1)$$

We have,

$= \frac12 (100)(101) - 3 \cdot \frac12 (33)(34) - 7\cdot \frac12 (14)(15) + 21 \cdot \frac12 (4)(5)$

$= 5050 - 1683 - 735 + 210$

$= 2842$

If you can use programmatic approach to answer your questions, which I personally find way easier than hand-written-math, you can check out that simple JavaScript fiddle I wrote for you.

In the right bottom corner you can find answers for you questions.

You can easily change code to, for example, find all numbers in range 100-1000 if you need to.
In that case, you would have to change line:

for (var i = 1; i <= 100; i++) {


to:

for (var i = 100; i <= 1000; i++) {


Every time you want your output to update, you have to click Run button at the top.

Remember that the bottom right window won't wrap text, so the horizontal scrolling is possible.

• For text wrap, include spaces in the output. Hint: Array.join(", ") – Jo Are By Jan 3 '17 at 9:43
• Other way to fix text wrap, is to add this line in CSS (top-right): div { word-wrap: break-word; } – deshu Jan 3 '17 at 16:47

First posted as a hint, but now it is the compilation to @Atul Mishra's answer.

Let us see what is happening in diagrammatic way:

Now, look at the image carefully.The coloured regions represent following data:

The rectangle: Sum of All the numbers from $1-100$.

White region: Sum of Numbers that are neither multiple of $3$ nor of $7$.

Green region: Sum of Numbers that are multiple of $3$ only.

Blue region: Sum of Numbers that are multiple of $7$ only.

Light blue region: Sum of Numbers that are multiple of $3$ and $7$.

We have to find the sum of numbers which are neither divisible by $3$ nor by $7$. So, we will find the sum of numbers that are in white region.

Sum of Numbers in white region $=$ Sum of Numbers in Rectangle $-$ Sum of Numbers in (Dark blue $+$ Light Blue) $-$ Sum of Numbers in (Green + Light Blue) $+$ Sum of Numbers in light blue region.

From here we get the formula used by other answers. i.e.,

Sum of Required numbers $=$ Sum of Total Numbers $-$ Sum of Numbers divisible by $7-$ Sum of Numbers divisible by $3+$ Sum of Numbers divisible by both $3$ and $7$.

Next question you may ask is that, How to find the sum of numbers from $1-100$ or sum of multiples of $3$ etc.

There is no problem in it, you just have to identify the A.P.

Sum of numbers from $1$ to $100$ equals $\frac{100}{2}\times {101}$.

Sum of multiples of $3$ equals $\frac{33}{2}\times 102$. ...... ...... ......

I think I shall let you conclude now. :) :) :)