How to check prime number

i am having trouble in sequence of generating prime number upto given n.

The naive way of checking it would be to iterate from 2 to square root of that number if no number in that range divides the given number then it is prime otherwise it is not.

1 Like