A Silly Algorithm for Prime Factorization

p = sqrt(n)
q = n / p
num_runs = 0
while abs(int(p) - p) > 0 and abs(int(q) - q) > 0:
if num_runs % 2 == 0
p = ceil(p)
q = n / p
else
q = floor(q)
p = n / q
num_runs += 1
return p, q

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store