ปานกลาง 0 ข้อที่แก้แล้ว อัตราผ่าน 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.

เงื่อนไข

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

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
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.

ตัวอย่างที่ 2
อินพุต:
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 กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก