Beispiel #1
0
def main():
    lst = array.array('Q', (1 for _ in range(LIMIT)))
    lst[0] = 0
    for i in range(2, LIMIT):
        square = i * i
        for j in range(i, LIMIT, i):
            lst[j] += square
    return sum(i for i, n in enumerate(lst) if euler.is_square(n))
Beispiel #2
0
def check_goldbach(n):
	prime_ptr = 0
	while(True):
		prime = sieve[prime_ptr]
		if prime > n:
			break
		if euler.is_square((n - prime)/2):
			return True
		prime_ptr += 1
	return False
Beispiel #3
0
def continued_fraction_period(n):
    if is_square(n):
        return 0
    a_0 = floor(n ** 0.5)
    m, d, a = 0, 1, a_0
    ans = 0
    while a != 2 * a_0:
        m = d * a - m
        d = (n - m ** 2) / d
        a = floor((a_0+m) / d)
        ans += 1
    return ans
Beispiel #4
0
def continued_fraction_cycle(n):
    if is_square(n):
        return 0
    a_0 = int(floor(n ** 0.5))
    m, d, a = 0, 1, a_0
    L = [a_0]
    while a != 2 * a_0:
        m = d * a - m
        d = (n - m ** 2) / d
        a = int(floor((a_0+m) / d))
        L.append(a)
    return L
Beispiel #5
0
def calculate(trio1, trio2):
    d, e, a = trio1
    f, c, a = trio2
    if c < e:
        d, e, f, c = f, c, d, e
    b_2 = c * c - e * e
    if euler.is_square(b_2):
        x_2 = a * a + b_2
        if x_2 % 2 == 0:
            x = x_2 // 2
            y = a * a - x
            z = c * c - x
            b = euler.int_sqrt(b_2)
            x_y_z = int(x + y + z)
            return x_y_z, min(a, b, c, d, e, f), max(a, b, c, d, e, f)
    return None, None, None
Beispiel #6
0
def find_minimal_x(D):
    if is_square(D):
        return 0
    a = continued_fraction_cycle(D)
    h_1, h_2 = 1, a[0]
    k_1, k_2 = 0, 1
    a = a[1:]
    i = 0
    h_1, h_2 = h_2, a[i] * h_2 + h_1
    k_1, k_2 = k_2, a[i] * k_2 + k_1
    i = (i + 1) % len(a)
    while h_2 ** 2 - D * k_2 ** 2 != 1:
        h_1, h_2 = h_2, a[i] * h_2 + h_1
        k_1, k_2 = k_2, a[i] * k_2 + k_1
        i = (i + 1) % len(a)
    return h_2