'Coding has over 700 languages', '67% of programming jobs aren’t in the technology industry', 'Coding is behind almost everything that is powered by electricity'
Topics

Find prime numbers

Easy
0/40
Average time to solve is 15m

Problem statement

You are given a positive integer ‘N’. Your task is to print all prime numbers less than or equal to N.

Note: A prime number is a natural number that is divisible only by 1 and itself. Example - 2, 3, 17, etc.

You can assume that the value of N will always be greater than 1. So, the answer will always exist.

Detailed explanation ( Input/output format, Notes, Images )
Constraints:
``````2 <= N <= 10^7

Where ‘N’ is the given positive integer.

Time Limit: 1sec
``````
Sample Input 1 :
``````7
``````
Sample Output 1 :
``````2 3 5 7
``````

Sample Output 1 Explanation:

``````For the given input, all prime numbers from 2 to 7 are 2, 3, 5 and 7.
``````
Sample Input 2 :
``````30
``````
Sample Output 2 :
``````2 3 5 7 11 13 17 19 23 29
``````
Console