Package g2601_2700.s2652_sum_multiples
Class Solution
java.lang.Object
g2601_2700.s2652_sum_multiples.Solution
2652 - Sum Multiples.<p>Easy</p>
<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 the constraint.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 7</p>
<p><strong>Output:</strong> 21</p>
<p><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>.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 10</p>
<p><strong>Output:</strong> 40</p>
<p><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.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 9</p>
<p><strong>Output:</strong> 30</p>
<p><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>.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 10<sup>3</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
sumOfMultiples
public int sumOfMultiples(int n)
-