Вот условие:
Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.
Return an integer denoting the sum of all numbers in the given range satisfying the constraint.
Example 1:
Input: n = 7
Output: 21
Explanation: Numbers in the range [1, 7] that are divisible by 3, 5, or 7 are 3, 5, 6, 7. The sum of these numbers is 21.
я написал решение
class Solution {
public:
int sumOfMultiples(int n) {
vector<short> arr;
short count = 0;
for (short i = 0; i < n; ++i)
arr.push_back(i);
for (const short& x : arr)
if (x % 3 == 0 || x % 5 == 0 || x % 7 == 0)
count += x;
return count;
}
};
но вместо того, чтобы выводить 21 как в примере, он выводит 14, что не так?