Exemplo n.º 1
0
def lehman_simple(n): # Find a nontrivial factor m of n; if n prime then m==n
# Pre: n > 1
# Post: return m; m > 1, n % m == 0; m == n only if n is prime
	n_1_3 = int(ceil(pow(n, 1.0/3.0)))
	n_1_6 = pow(n, 1.0/6.0)
	# 1. Trial division
	ub_d = max(n_1_3, 19) # Ensures n > 21 in step 2.
	for d in range(2,ub_d+1):
		if n % d == 0: return d
	# 2. Loop
	for k in range(1,n_1_3+1):
		lb = int(ceil(2*sqrt(k*n)))
		ub = int(floor(2*sqrt(k*n) + n_1_6/(4*sqrt(k))))
		for a in range(lb, ub+1):
			delta = a*a - 4*k*n
			b = int(floor(sqrt(delta)))
			if b*b == delta: 
				return GCD.gcd(a+b, n)
	return n
Exemplo n.º 2
0
def gcd(a):
	gcd = a[0]
	for x in a:
		gcd = GCD.gcd(x, gcd)
	return gcd
Exemplo n.º 3
0
def DecimalExpansion(n):
    for x in range(1, 2000):
        if((10**x) % n == 1 and GCD.gcd(10, n)):
            return x
    return -1