#C3391. Sum of Primes

    ID: 46813 Type: Default 1000ms 256MiB

Sum of Primes

Sum of Primes

Given an integer \(N\), your task is to compute the sum of all prime numbers less than or equal to \(N\). A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself. The most efficient approach for this problem involves using the Sieve of Eratosthenes. In this algorithm, we mark non-prime numbers in a list from 2 to \(N\). The iteration runs up to \(\sqrt{N}\) (i.e. \(\lfloor \sqrt{N}\rfloor\)), which guarantees that every composite number will have a factor less than or equal to \(\sqrt{N}\).

Example: For \(N = 10\), the prime numbers are 2, 3, 5, and 7. Their sum is \(2 + 3 + 5 + 7 = 17\).

inputFormat

The input consists of a single integer \(N\) provided via stdin.

\(1 \leq N \leq 10^5\) (or any reasonable limit as per language constraints).

outputFormat

Output a single integer which is the sum of all prime numbers less than or equal to \(N\), printed to stdout.

## sample
10
17