Prime Numbers in Interval Problem Statement

You are provided with a positive integer N. Your task is to return all the prime numbers that are less than or equal to N.

Input:

The input consists of an integer 'T' representing the number of test cases. Each test case contains one integer 'N'.

Output:

For each test case, return a list of prime numbers less than or equal to 'N' in ascending order.

Example:

Input:
3
10
5
20
Output:
[2, 3, 5, 7]
[2, 3, 5]
[2, 3, 5, 7, 11, 13, 17, 19]
Note:
  • A prime number is a number greater than 1 that has no factors other than 1 and itself.
  • 1 is not considered a prime number.
  • No need to print the output; just implement the function to return the desired output.

Constraints:

  • 1 <= T <= 100
  • 2 <= N <= 5000

Time Limit: 1 second

AnswerBot
10d

Return all prime numbers less than or equal to a given positive integer N.

  • Create a function that takes an integer N as input

  • Iterate from 2 to N and check if each number is prime

  • Return a list of prime ...read more

Help your peers!
Add answer anonymously...
UnitedHealth Business Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter