모든 챌린지
쉬움 0명 해결 정답률 0%

Sum of Multiples

Add values below a limit divisible by any supplied factor.

Consider positive integers strictly below limit. Include a value if it is divisible by at least one nonzero factor. Count each included value once even if several factors divide it. Ignore zero factors. Factors [3, 5] give the familiar multiples-of-3-or-5 task.

Implement sum_of_multiples(limit, factors).

Input

limit: The exclusive upper bound.

factors: The factors whose multiples are eligible.

Output

Return the sum of distinct eligible positive integers.

제약 조건

0 ≤ limit ≤ 100,000. There may be 0 through 20 factors, each between 0 and 100,000. Duplicate factors are allowed.

예시

예시 1
입력:
limit = 12
factors = [3, 5]

예상 출력:
expected = 33
입력:
long long limit = 12;
std::vector<long long> factors = {3, 5};

예상 출력:
long long expected = 33;
입력:
long limit = 12;
long[] factors = new long[] {3, 5};

예상 출력:
long expected = 33;

설명

The included values are 3, 5, 6, 9, and 10. Their sum is 33.

예시 2
입력:
limit = 10
factors = [2, 4]

예상 출력:
expected = 20
입력:
long long limit = 10;
std::vector<long long> factors = {2, 4};

예상 출력:
long long expected = 20;
입력:
long limit = 10;
long[] factors = new long[] {2, 4};

예상 출력:
long expected = 20;

설명

Include 2, 4, 6, and 8. Values 4 and 8 are counted once despite matching both factors.

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.