#K47747. Sum of Primes
Sum of Primes
Sum of Primes
Given an integer \(N\), your task is to calculate the sum of all prime numbers less than or equal to \(N\). A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
You will be given \(T\) test cases. For each test case, you need to compute and output the sum of all prime numbers \(p\) such that \(p \leq N\). An efficient way to achieve this is to use the Sieve of Eratosthenes algorithm to generate the list of primes up to \(N\).
Input Format: The first line contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains a single integer \(N\).
Output Format: For each test case, print the sum of all prime numbers less than or equal to \(N\) on a new line.
Note: Use stdin to read input and stdout to write output.
inputFormat
The first line of input contains an integer \(T\) denoting the number of test cases. The next \(T\) lines each contain one integer \(N\).
Example: 3 10 5 30
outputFormat
For each test case, output a single line containing the sum of all prime numbers less than or equal to \(N\).
Example: 17 10 129## sample
3
10
5
30
17
10
129
</p>