def find1(N, A=None): if A == None: A = gmpy.mpz(gmpy.sqrt(N) + 1) k = A * A - N assert gmpy.is_power(k) x = gmpy.sqrt(A * A - N) p, q = A - x, A + x #print p #print q assert gmpy.is_prime(p) assert gmpy.is_prime(q) assert p * q == N return p, q
def find1(N, A = None): if A == None: A = gmpy.mpz(gmpy.sqrt(N)+1) k = A*A - N assert gmpy.is_power(k) x = gmpy.sqrt(A*A - N) p, q = A - x, A + x #print p #print q assert gmpy.is_prime(p) assert gmpy.is_prime(q) assert p*q==N return p, q
def find3(N, A=None): if A == None: A = gmpy.mpz(gmpy.sqrt(24 * N) + 1) k = A * A - 24 * N assert gmpy.is_power(k) x = gmpy.sqrt(k) print x q1 = (A - x) / 4 p1 = (A + x) / 6 q2 = (A + x) / 4 p2 = (A - x) / 6 if gmpy.is_prime(p1) and gmpy.is_prime(q1) and p1 * q1 == N: return p1, q1 elif gmpy.is_prime(p2) and gmpy.is_prime(q2) and p2 * q2 == N: return p2, q2 else: assert False
def find3(N, A = None): if A == None: A = gmpy.mpz(gmpy.sqrt(24*N)+1) k = A*A - 24*N assert gmpy.is_power(k) x = gmpy.sqrt(k) print x q1 = (A - x)/4 p1 = (A + x)/6 q2 = (A + x)/4 p2 = (A - x)/6 if gmpy.is_prime(p1) and gmpy.is_prime(q1) and p1*q1==N: return p1, q1 elif gmpy.is_prime(p2) and gmpy.is_prime(q2) and p2*q2==N: return p2, q2 else: assert False