Skip to content

Instantly share code, notes, and snippets.

@seanballais
Created April 28, 2018 14:29
Show Gist options
  • Save seanballais/04c8d240fa7a9eb5d44759410d2d18a7 to your computer and use it in GitHub Desktop.
Save seanballais/04c8d240fa7a9eb5d44759410d2d18a7 to your computer and use it in GitHub Desktop.
Obtaining the Prime Factors of a Semiprime
import math
def obtain_pq(n):
p = 0.1
k = math.ceil(math.sqrt(n))
while not p.is_integer():
p = k - math.sqrt((k ** 2) - n)
k += 1
q = int(n / p)
p = int(p)
return p, q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment