<p>Given a positive integer <code>n</code>, find the sum of all integers in the range <code>[1, n]</code> <strong>inclusive</strong> that are divisible by <code>3</code>, <code>5</code>, or <code>7</code>.</p>

<p>Return <em>an integer denoting the sum of all numbers in the given range satisfying&nbsp;the constraint.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 7
<strong>Output:</strong> 21
<strong>Explanation:</strong> Numbers in the range <code>[1, 7]</code> that are divisible by <code>3</code>, <code>5,</code> or <code>7 </code>are <code>3, 5, 6, 7</code>. The sum of these numbers is <code>21</code>.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 10
<strong>Output:</strong> 40
<strong>Explanation:</strong> Numbers in the range <code>[1, 10] that are</code> divisible by <code>3</code>, <code>5,</code> or <code>7</code> are <code>3, 5, 6, 7, 9, 10</code>. The sum of these numbers is 40.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> n = 9
<strong>Output:</strong> 30
<strong>Explanation:</strong> Numbers in the range <code>[1, 9]</code> that are divisible by <code>3</code>, <code>5</code>, or <code>7</code> are <code>3, 5, 6, 7, 9</code>. The sum of these numbers is <code>30</code>.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>3</sup></code></li>
</ul>

from math import floor

class Solution:
    def sumOfMultiples(self, n: int) -> int:
        
# my goal is to do without a loop -- though we are in 10^3 max
        # c = 0
        # for i in range(1, n+1):
        #     if i%3 == 0 or i%5 == 0 or i %7 == 0:
        #         c += i
        # return c 

        # math based solution
        div3 = floor(n/3) 
        div5 = floor(n/5)
        div7 = floor(n/7)
        
        div15 = floor(n/15)
        div35 = floor(n/35)
        div21 = floor(n/21)

        # print(div3, div5, div7)

        div105 = floor(n/(3*5*7))

        s3 = (div3*(div3+1)/2)*3
        s5 = (div5*(div5+1)/2)*5
        s7 = (div7*(div7+1)/2)*7

        # print(s3, s5, s7)

        s15 = (div15*(div15+1)/2)*15
        s21 = (div21*(div21+1)/2)*21
        s35 = (div35*(div35+1)/2)*35

        s105 = (div105*(div105+1)/2)*105


        counter = int(s3+s5+s7 - s15-s21-s35 + s105)

        return counter


29