


1) A prime number is a number that has only two factors: 1 and the number itself.
2) 1 is not a prime number.
The first line contains an integer 'T', which denotes the number of test cases or queries to be run. Then, the 'T' test cases follow.
The first line of each test case contains only one integer 'N', as described in the problem statement.
For each test case, return a sequence of integers denoting the prime number less than or equal to 'N' in the increasing order.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 100
2 <= N <= 5000
Time Limit: 1sec
The idea here is to check every number less than or equal to N is prime or not. Those who are prime just add them in an array and return the array at the end of the function.
bool 'IS_PRIME'(int n):
The idea here is similar to approach 1, which is to check every number less than or equal to ‘N’ is prime or not. The difference is that we are not running a loop till ‘N-1’ to check whether ‘N’ is prime or not in this approach.
It is clear that if ‘i’ divides ‘N’ completely, then ‘N/i’ also divides ‘N’ completely. So, we just run a loop to the square root of ‘N’ by using the above property. Those who are prime just add them into the array and return the array at the end of the function.
bool 'IS_PRIME'(int n):
The idea here to use the Sieve of Eratosthenes. Sieve of Eratosthenes is used to find all the prime numbers less than or equal to ‘N’. It creates a boolean array of size ‘N+1’ and marks all the entries as true. After the function ends, all the entries marked with false are not the prime numbers.
int[] 'SIEVE_OF_ERATOSTHENES'(int N):