Given a positive integer n your task is to print prime numbers up to the number n starting from 2.

Sample Input: 5

Sample Output:
2
3
5

Solution

n=int(input())
for x in [x for x in range(2, n+1) if all(x % y != 0 for y in range(2, x))]:
    print(x)

Comments