Условие
Показать перевод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.
Примеры
Ввод:
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.
Ввод:
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. Следуйте условию и ограничениям выше.