Ejemplo n.º 1
0
 def find_by_k(self):
     """
     a = 3k - 1
     b = k
     c = 8 * k - 3
     :return:
     """
     self.triplets = []
     for bk in range(1, self.get_max_q()):
         ck = (8 * bk - 3)
         ak = 3 * bk - 1
         sq_d = self.get_square_dividers(ck)
         if ak + bk + ck > self.limit:
             if mylib.is_prime(ck) and not len(sq_d):
                 continue
         m0 = mylib.mult(sq_d)
         b0 = bk * m0
         c0 = int(ck / m0 / m0)
         if c0 > self.limit - ak - 1:
             continue
         b_limit = self.limit - ak - c0
         bm_bm = [(x, int(b0 / x) ** 2) for x in mylib.find_composite_dividers(b0, b_limit)]
         for bm in bm_bm:
             b = bm[0]
             c = c0 * bm[1]
             if ak + b + c > self.limit:
                 continue
             t = [ak, b, c]
             self.triplets.append(t)
             print(t, len(self.triplets))
         continue
     return self
Ejemplo n.º 2
0
 def find_by_k(self):
     """
     a = 3k - 1
     b = k
     c = 8 * k - 3
     :return:
     """
     self.triplets = []
     for bk in range(1, self.get_max_q()):
         ck = (8 * bk - 3)
         ak = 3 * bk - 1
         sq_d = self.get_square_dividers(ck)
         if ak + bk + ck > self.limit:
             if mylib.is_prime(ck) and not len(sq_d):
                 continue
         m0 = mylib.mult(sq_d)
         b0 = bk * m0
         c0 = int(ck / m0 / m0)
         if c0 > self.limit - ak - 1:
             continue
         b_limit = self.limit - ak - c0
         bm_bm = [(x, int(b0 / x)**2)
                  for x in mylib.find_composite_dividers(b0, b_limit)]
         for bm in bm_bm:
             b = bm[0]
             c = c0 * bm[1]
             if ak + b + c > self.limit:
                 continue
             t = [ak, b, c]
             self.triplets.append(t)
             print(t, len(self.triplets))
         continue
     return self
Ejemplo n.º 3
0
def find_2mn(a):
    out = []
    if a % 2:
        return out
    dd = mylib.find_composite_dividers(a // 2)
    _dd = dd[::-1]
    l = len(dd)
    # print(a, dd)
    for i in range(l // 2):
        d = _dd[i]**2 - dd[i]**2
        if d > 2 * a:
            continue
        t = (a, d)
        out.append(t)
    return out
Ejemplo n.º 4
0
def find_2mn(a):
    out = []
    if a % 2:
        return out
    dd = mylib.find_composite_dividers(a // 2)
    _dd = dd[::-1]
    l = len(dd)
    # print(a, dd)
    for i in range(l // 2):
        d = _dd[i] ** 2 - dd[i] ** 2
        if d > 2 * a:
            continue
        t = (a, d)
        out.append(t)
    return out
Ejemplo n.º 5
0
 def solve():
     m = 100000000
     data = [2]
     for a in range(6, m, 4):
         if not mylib.is_prime(a + 1) or not mylib.is_prime(a / 2 + 2):
             continue
         dd = mylib.find_composite_dividers(a)
         if len(dd) % 2:
             continue
         # print(a, dd)
         all_primes = True
         for i in range(2, len(dd) // 2):
             b = dd[i] + dd[len(dd) - i - 1]
             all_primes = all_primes and mylib.is_prime(b)
             # print('   ', dd[i], dd[len(dd) - i - 1], b, all_primes)
             if not all_primes:
                 break
         if all_primes:
             print(a, dd)
             data.append(a)
     # print(data)
     return sum(data)
Ejemplo n.º 6
0
     else:
         # print(x, '-', 'prime, 4k+1: impossible')
         continue
 if x % 4 == 1:
     # print(x, '-', '(2k+1)(2(k+2p) + 1): impossible')
     continue
 if x % 4 == 2:
     # print(x, '-', '2(2k+1): impossible')
     continue
 if x % 4 == 3:
     # print(x, '-', '(2k+1)(2(k+2p+1)+1): at least 2 ways')
     continue
 if x % 16 and not x % 8:
     # print(x, '-', '8(2k+1): impossible')
     continue
 dd = mylib.find_composite_dividers(x)
 min_a = (x / 3)**0.5
 rr = []
 for i in range(len(dd)):
     a = dd[i]
     if a <= min_a:
         continue
     z = dd[-1 - i]
     s = a + z
     if s % 4:
         continue
     b = int(s / 4)
     pr = (x + b, x, x - b)
     rr.append(pr)
     if len(rr) > 1:
         break
Ejemplo n.º 7
0
def ww_to_n(w_list):
    out = 1
    for x in w_list:
        out *= w_list[x] + 1
    return out


m = 0
s = 2 * 3 * 5 * 7
for n in range(s, 1000, s):
    if mylib.is_prime(n):
        continue
    pd = mylib.find_dividers(n)
    if len(pd) < 4:
        continue
    dd = mylib.find_composite_dividers(n)
    print(n, len(dd), dd)
    ss = set()
    for a in dd:
        for b in dd:
            if b > a:
                continue
            if mylib.find_gcd(a, b) > 1:
                continue
            z = a + b
            x = round(n * z / b)
            y = round(n / a) * z
            print(a, b, x, y, x * y / (x + y))
            ss.add((min(x, y), max(
                x,
                y,
Ejemplo n.º 8
0
uu = []
for t in ttb:
    u = (t[0], t[1] + t[2])
    if u not in uu:
        uu.append(u)

y = 0
uu1 = []
stored_tt = dict()
for a in range(1, M + 1):
    clean_tt = find_mm_nn(a) + find_2mn(a)

    stored_tt[a] = clean_tt
    tt = clean_tt[:]
    dd = mylib.find_composite_dividers(a)
    for d in dd:
        if d < 3 or d == a:
            continue
        if d in stored_tt:
            # print(a, 'stored', stored_tt[d])
            for t in stored_tt[d]:
                t1 = (a, t[1] * a // d)
                if t1 not in tt:
                    # print(a, ' <- ', t1)
                    tt.append(t1)
                # tt += [x for x in stored_tt[d]]
    uu1 += tt
    if not len(tt):
        continue
    z = 0
Ejemplo n.º 9
0
def ww_to_n(w_list):
    out = 1
    for x in w_list:
        out *= w_list[x] + 1
    return out


m = 0
s = 2 * 3 * 5 * 7
for n in range(s, 1000, s):
    if mylib.is_prime(n):
        continue
    pd = mylib.find_dividers(n)
    if len(pd) < 4:
        continue
    dd = mylib.find_composite_dividers(n)
    print(n, len(dd), dd)
    ss = set()
    for a in dd:
        for b in dd:
            if b > a:
                continue
            if mylib.find_gcd(a, b) > 1:
                continue
            z = a + b
            x = round(n * z / b)
            y = round(n / a) * z
            print(a, b, x, y, x * y / (x + y))
            ss.add((min(x, y), max(x, y, )))

    sl = len(ss)
Ejemplo n.º 10
0
import mylib

bb = {}
cc = {}
m = 10 ** 6 + 1
longest = (0,)
for a in range(m):
    if a in cc:
        continue

    b = sum(mylib.find_composite_dividers(a)[:-1])
    if a == b:
        cc[a] = (), (b,)
        continue
    c = [a]

    x = a
    y = sum(mylib.find_composite_dividers(x)[:-1])
    c_prefix = None
    c_amicable = None
    while y not in c:
        # print(y)
        if y in cc:
            c_prefix = tuple(c) + cc[y][0]
            c_amicable = cc[y][1]
            break
        c.append(y)
        if y > m:
            break
        x = y
        y = sum(mylib.find_composite_dividers(x)[:-1])