Пример #1
0
def main(limit):
    # Case 1: a, a, a + 1
    #	for integer area a must be odd, a = 2 * k1 + 1
    #	this leads to:
    #		p1 = 3*a + 1 = 6*k1 + 4
    #		(3*k1+1)^2 - 3*s^2 = 1 for some integer s
    # Case 2: a, a, a - 1
    #	for integer area a must be odd, a = 2 * k2 + 1
    #	this leads to:
    #		p2 = 3*a - 1 = 6*k2 + 2
    #		(3*k2+2)^2 - 3*s^2 = 1 for some integer s

    rv = 0
    # get all t and s such that t^2 - 3*s^2 = 1
    for x, y in convergents(3):
        if x >= 4 and x * x - 3 * y * y == 1:
            t = x
            p1 = 2 * (t - 1) + 4
            p2 = 2 * (t - 2) + 2
            if p1 > limit and p2 > limit:
                return rv
            if p1 <= limit and (t - 1) % 3 == 0:
                rv += p1
            if p2 <= limit and (t - 2) % 3 == 0:
                rv += p2
Пример #2
0
def main(limit):
    # Case 1: a, a, a + 1
    # 	for integer area a must be odd, a = 2 * k1 + 1
    # 	this leads to:
    # 		p1 = 3*a + 1 = 6*k1 + 4
    # 		(3*k1+1)^2 - 3*s^2 = 1 for some integer s
    # Case 2: a, a, a - 1
    # 	for integer area a must be odd, a = 2 * k2 + 1
    # 	this leads to:
    # 		p2 = 3*a - 1 = 6*k2 + 2
    # 		(3*k2+2)^2 - 3*s^2 = 1 for some integer s

    rv = 0
    # get all t and s such that t^2 - 3*s^2 = 1
    for x, y in convergents(3):
        if x >= 4 and x * x - 3 * y * y == 1:
            t = x
            p1 = 2 * (t - 1) + 4
            p2 = 2 * (t - 2) + 2
            if p1 > limit and p2 > limit:
                return rv
            if p1 <= limit and (t - 1) % 3 == 0:
                rv += p1
            if p2 <= limit and (t - 2) % 3 == 0:
                rv += p2
Пример #3
0
def main(limit):
    # B*(B-1)/T/(T-1) = 1/2		=>		2*(2*B-1)^2 - (2*T-1)^2 = 1
    # the solutions are the odd convergents of the Pell equation y^2 - 2*x^2 = -1
    for x, y in convergents(2):
        if x % 2 == 1 and y % 2 == 1 and x * x - 2 * y * y == -1:
            blue = (y + 1) // 2
            total = (x + 1) // 2
            if total > limit:
                return blue
Пример #4
0
def main(limit):
	# B*(B-1)/T/(T-1) = 1/2		=>		2*(2*B-1)^2 - (2*T-1)^2 = 1
	# the solutions are the odd convergents of the Pell equation y^2 - 2*x^2 = -1
	for x, y in convergents(2):
		if x % 2 == 1 and y % 2 == 1 and x * x - 2 * y * y == -1:
			blue = (y + 1) // 2
			total = (x + 1) // 2
			if total > limit:
				return blue
Пример #5
0
def minX(D):
	for x, y in convergents(D):
		if x * x - D * y * y == 1:
			return x
	return float('-inf')
Пример #6
0
def goodConvergentsOf(D):
    for x, y in convergents(D):
        if x > 2 and x * x - D * y * y == -1:
            yield x, y
Пример #7
0
def goodConvergentsOf(D):
	for x, y in convergents(D):
		if x > 2 and x * x - D * y * y == -1:
			yield x, y