#C7134. Sieve of Eratosthenes: Prime Numbers Generation
Sieve of Eratosthenes: Prime Numbers Generation
Sieve of Eratosthenes: Prime Numbers Generation
This problem requires you to implement the Sieve of Eratosthenes algorithm to generate all prime numbers up to a given value n. The algorithm operates in O(n \( \log \log n \)) time complexity and is one of the most efficient ways to identify primes in a given range.
You will be given several test cases. For each test case, read an integer n and generate a list of all prime numbers less than or equal to n in ascending order. If no prime number exists (for example, when n is less than 2), output an empty line.
Note: All formulas required are presented in LaTeX format.
inputFormat
The input is read from stdin and has the following format:
T n₁ n₂ ... nT
where T is the number of test cases and each nᵢ is an integer indicating the upper limit for generating prime numbers.
outputFormat
For each test case, output a single line on stdout containing all prime numbers up to n separated by a single space. If there are no prime numbers, print an empty line.
## sample1
10
2 3 5 7
</p>