All Prime Numbers Less Than or Equal to N
Given a positive integer N
, your task is to return all the prime numbers less than or equal to N
.
Note:
1) A prime number is a number that has only two factors: 1 and the number itself.
2) 1 is not a prime number.
Input:
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.
Output:
For each test case, return a sequence of integers denoting the prime numbers less than or equal to 'N' in increasing order.
Example:
Input:
T = 2
N = 10
N = 20
Output:
2, 3, 5, 7
2, 3, 5, 7, 11, 13, 17, 19
Constraints:
1 <= T <= 100
2 <= N <= 5000
- Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
Top Facebook Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app