Skip to content

Instantly share code, notes, and snippets.

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 Denenberg/94389c3d59c83092a4b66df6d9a2f6a8 to your computer and use it in GitHub Desktop.
Save Denenberg/94389c3d59c83092a4b66df6d9a2f6a8 to your computer and use it in GitHub Desktop.
Here's a simple Python program that prints the first n numbers each of them is a product of 1 distinct primes:
# Here's a simple Python program that prints the first n numbers
# each of them is a product of 1 distinct primes:
# This program uses a simple algorithm to generate
# prime numbers up to a certain limit (n), and then prints the
# first n prime numbers.
def get_primes(n):
primes = []
candidate = 2
while len(primes) < n:
is_prime = True
for prime in primes:
if candidate % prime == 0:
is_prime = False
break
if is_prime:
primes.append(candidate)
candidate += 1
return primes
def main():
n = int(input("Enter the number of prime products to print: "))
primes = get_primes(n)
for i in range(n):
print(primes[i])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment