Problem
Übersetzung anzeigenA 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.
Einschränkungen
0 ≤ limit ≤ 2,000,000. Return the sum using a signed 64-bit integer.
Beispiele
Eingabe:
limit = 12
Erwartete Ausgabe:
expected = 28
Eingabe:
long long limit = 12;
Erwartete Ausgabe:
long long expected = 28;
Eingabe:
long limit = 12;
Erwartete Ausgabe:
long expected = 28;
Erläuterung
The primes below 12 are 2, 3, 5, 7, and 11; their sum is 28.
Eingabe:
limit = 2
Erwartete Ausgabe:
expected = 0
Eingabe:
long long limit = 2;
Erwartete Ausgabe:
long long expected = 0;
Eingabe:
long limit = 2;
Erwartete Ausgabe:
long expected = 0;
Erläuterung
There are no primes strictly below 2.
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.