Tous les défis
Moyen 0 résolus 0 % de réussite

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.

Contraintes

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

Exemples

Exemple 1
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.

Exemple 2
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.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.