Tất cả thử thách
Trung bình 0 đã giải Tỷ lệ chấp nhận 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.

Ràng buộc

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

Ví dụ

Ví dụ 1
Đầu vào:
limit = 12

Kết quả mong đợi:
expected = 28
Đầu vào:
long long limit = 12;

Kết quả mong đợi:
long long expected = 28;
Đầu vào:
long limit = 12;

Kết quả mong đợi:
long expected = 28;

Giải thích

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

Ví dụ 2
Đầu vào:
limit = 2

Kết quả mong đợi:
expected = 0
Đầu vào:
long long limit = 2;

Kết quả mong đợi:
long long expected = 0;
Đầu vào:
long limit = 2;

Kết quả mong đợi:
long expected = 0;

Giải thích

There are no primes strictly below 2.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.