Problème
Afficher la traductionA 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.
Contraintes
0 ≤ limit ≤ 2,000,000. Return the sum using a signed 64-bit integer.
Exemples
Entrée :
limit = 12
Sortie attendue :
expected = 28
Entrée :
long long limit = 12;
Sortie attendue :
long long expected = 28;
Entrée :
long limit = 12;
Sortie attendue :
long expected = 28;
Explication
The primes below 12 are 2, 3, 5, 7, and 11; their sum is 28.
Entrée :
limit = 2
Sortie attendue :
expected = 0
Entrée :
long long limit = 2;
Sortie attendue :
long long expected = 0;
Entrée :
long limit = 2;
Sortie attendue :
long expected = 0;
Explication
There are no primes strictly below 2.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.