簡単 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用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。