<s>[INST] 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 ?
 [/INST] 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.

Update -  Answer with explanation.

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$
</s>