すべてのチャレンジ
中級 0件解決済み 正答率0%

Sum of Primes Below a Limit

Add all primes strictly below a limit.

A prime is an integer greater than 1 divisible only by 1 and itself. Add every prime strictly smaller than limit. The limit itself is excluded even when it is prime.

Implement prime_sum(limit).

Input

limit: The exclusive upper bound.

Output

Return the sum of the eligible primes, or 0 when none exist.

制約

0 ≤ limit ≤ 2,000,000. Return the sum using a signed 64-bit integer.

例

例 1
入力:
limit = 12

期待される出力:
expected = 28
入力:
long long limit = 12;

期待される出力:
long long expected = 28;
入力:
long limit = 12;

期待される出力:
long expected = 28;

解説

The primes below 12 are 2, 3, 5, 7, and 11; their sum is 28.

例 2
入力:
limit = 2

期待される出力:
expected = 0
入力:
long long limit = 2;

期待される出力:
long long expected = 0;
入力:
long limit = 2;

期待される出力:
long expected = 0;

解説

There are no primes strictly below 2.

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

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