def test3(limit): matches = [16] test = 15 interval = 1 direction = 1 ratio = 3 while matches[-1] < limit: if test % 2 == 0: h1 = heron_area_squared(test, test + 1, test + 1) if is_perfect_square(h1): perimeter = test + test + 1 + test + 1 ratio = perimeter / matches[-1] matches.append(perimeter) test = int(test * ratio) interval = 1 continue else: h2 = heron_area_squared(test, test, test + 1) if is_perfect_square(h2): perimeter = test + test + test + 1 # ratio = perimeter / matches[-1] matches.append(perimeter) test = int(test * ratio) interval = 1 continue test += interval * direction interval += 1 direction *= -1 return sum(matches[:-1])
def test(limit): a = 1 while a < limit: if a % 2 == 0: h1 = heron_area_squared(a, a + 1, a + 1) if is_perfect_square(h1): print(a, a + 1, a + 1, h1, (3 * a + 2) / 2) else: h2 = heron_area_squared(a, a, a + 1) if is_perfect_square(h2): print(a, a, a + 1, h2, (3 * a + 1) / 2) a += 1
def frac_decompose(n, p=None): if is_perfect_square(n): return 0 array = [int_sqrt(n)] p = p or int_sqrt(n) * 2 + 5 s = square_root(n, p) br = int_sqrt(n) * 2 + 5 while True: inc = 1 i = 1 while True: if i > br: return frac_decompose(n, p * 2) array.append(i + inc) x = long_div(*frac(array), p) array.pop() array.append(i) y = long_div(*frac(array), p) if (s > x) ^ (s > y): if inc > 1: inc = 1 array.pop() continue else: break array.pop() i += inc if i == 4 and inc == 1: inc = 10 if array[-1] == array[0] * 2: print(array) return len(array) - 1
def test4(limit): matches = [16] side1 = 6 direction = 1 ratio = 2 + sqrt(3) while matches[-1] < limit: side2 = side1 if side1 % 2 == 1 else side1 + 1 area_squared = heron_area_squared(side1, side2, side1 + 1) print(area_squared) if is_perfect_square(area_squared): perimeter = side1 + side2 + side1 + 1 matches.append(perimeter) side1 = int(side1 * ratio) direction *= -1 continue side1 += direction return sum(matches[:-1])
def is_possibly_odd_period(n, evens): if is_perfect_square(n - 1): return True prime_factors = set() divisor = 3 while not n % 2: if 2 in prime_factors: return False prime_factors.add(2) n //= 2 while divisor * divisor <= n: if not n % divisor: if divisor in evens: return False prime_factors.add(divisor) n //= divisor else: divisor += 2 if n in evens: return False return True
from math import sqrt, factorial from itertools import combinations from simplemath import is_perfect_square, int_sqrt c = lambda n, r: factorial(n) // (factorial(r) * factorial(n - r)) is_triple = lambda a, b: is_perfect_square(a**2 + b**2) def euclid(m, n): a = m**2 - n**2 b = 2 * m * n c = m**2 + n**2 return (a, b, c) def euclid_gen(max_legs): limit = int_sqrt(max_legs // 2) + 1 for i in range(1, limit): for j in range(i + 1, limit): yield euclid(j, i) def run(m): total = 0 for triple in euclid_gen(3 * m): total += score(sorted(triple), m) return total # 4x^2 > 3*lim # x^2 == 1.5*lim