OFFSET
1,2
COMMENTS
The algorithm finds a nontrivial factor of n. If it returns 1 then n is an odd prime or 1. It has heuristic running time O(n^(1/3 + eps)).
LINKS
William B. Hart, A One Line Factoring Algorithm, J. Aust. Math. Soc. 92 (2012), 61-69.
PROG
(Python)
from sympy.ntheory.primetest import is_square
from sympy.core.power import isqrt
from sympy import igcd
def a(n):
k = -1
while True:
k += n
s = isqrt(k) + 1
m = pow(s, 2, n)
if is_square(m):
return igcd(n, s - isqrt(m))
print([a(n) for n in range(1, 87)])
CROSSREFS
KEYWORD
nonn
AUTHOR
Peter Luschny, Jun 22 2024
STATUS
approved