Sum of prime numbers in a range
TypeScript
Medium
math
Task «Sum of prime numbers in a range»
Given two natural numbers A and B (A <= B). Find the sum of all prime numbers in the interval [A, B]. A prime number is a number greater than 1 that has exactly two divisors: 1 and itself. Implement an efficient algorithm using the Sieve of Eratosthenes. It is guaranteed that A, B <= 10^6.
Input Format
In the first line, two integers A and B are entered, separated by a space.
Output Format
Output one integer — the sum of prime numbers in the interval [A, B].
Examples
Example 1
INPUT
10 20
OUTPUT
60
Example 2
INPUT
1
42
OUTPUT
238
main.ts