Sum of squares of prime numbers in a range

Swift Medium math

Task «Sum of squares of prime numbers in a range»

Two natural numbers A and B are given (1 <= A <= B <= 10^6). Find the sum of squares of all prime numbers in the interval [A, B]. If there are no prime numbers in the range, output 0. Use the Sieve of Eratosthenes to pre-generate prime numbers up to B.

Input Format

Two natural numbers A and B, separated by a space.

Output Format

One integer — the sum of squares of prime numbers in the interval [A, B].

main.swift