You are given a positive integer N. Your task is to return the sum of the first N prime numbers, starting from 2.
A prime number is a natural number greater than 1 that has exactly two distinct positive divisors: 1 and itself. Generate the prime numbers in ascending order and calculate their sum until you have found the first N primes.
Input: N = 3
Output: 10
Explanation: The first three prime numbers are 2, 3, and 5. Their sum is 2 + 3 + 5 = 10.
Input: N = 5
Output: 28
Explanation: The first five prime numbers are 2, 3, 5, 7, and 11. Their sum is 2 + 3 + 5 + 7 + 11 = 28.
Input: N = 1
Output: 2
Explanation: The first prime number is 2, so the sum is 2.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
5
28
10
129