Skip to content

Instantly share code, notes, and snippets.

@hsfzxjy
Created September 19, 2022 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsfzxjy/ba8ebbfca8ebaae2be9c89b5daa47ff2 to your computer and use it in GitHub Desktop.
Save hsfzxjy/ba8ebbfca8ebaae2be9c89b5daa47ff2 to your computer and use it in GitHub Desktop.
from math import ceil, sqrt
def isprime(n):
for x in range(2, ceil(sqrt(n + 1))):
if n % x == 0:
return False
return True
def prime(n):
if n == 0:
return
print("2 ", end=" ")
counter = 1
x = 3
while counter < n:
if isprime(x):
print(x, "", end=" ")
counter += 1
x += 2
if counter % 10 == 0:
print()
n = int(input())
prime(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment