示例#1
0
def solve():
    coils = coil_generator()

    numbers_prime = []
    numbers_complex = []
    r = 1
    i = 0
    coil = []
    while r >= 0.1:
        coil = coils.__next__()
        # print(coil)
        for x in coil:
            if mylib.is_prime(x):
                numbers_prime.append(x)
            else:
                numbers_complex.append(x)
        # print(numbers_prime)
        # print(numbers_complex)
        # print(len(numbers_complex), len(numbers_prime))
        r = len(numbers_prime) / (1 + len(numbers_complex) + len(numbers_prime))
        i += 1
        print(i, r, len(numbers_complex), len(numbers_prime))
    # print(numbers_prime)
    # print(numbers_complex)
    print(coil)
    return i * 2 + 1
示例#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
示例#3
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
示例#4
0
def solve():
    coils = coil_generator()

    numbers_prime = []
    numbers_complex = []
    r = 1
    i = 0
    coil = []
    while r >= 0.1:
        coil = coils.__next__()
        # print(coil)
        for x in coil:
            if mylib.is_prime(x):
                numbers_prime.append(x)
            else:
                numbers_complex.append(x)
        # print(numbers_prime)
        # print(numbers_complex)
        # print(len(numbers_complex), len(numbers_prime))
        r = len(numbers_prime) / (1 + len(numbers_complex) +
                                  len(numbers_prime))
        i += 1
        print(i, r, len(numbers_complex), len(numbers_prime))
    # print(numbers_prime)
    # print(numbers_complex)
    print(coil)
    return i * 2 + 1
示例#5
0
def solve():
    n = 9
    r = True
    while r:
        if not mylib.is_prime(n):
            r = process_number(n)
        n += 2
    return True
示例#6
0
def process_number(n):
    rn = math.floor(n ** 0.5)
    for i in range(1, rn+1):
        k = n -  2 * i ** 2
        #print(n, rn, i, k)
        if mylib.is_prime(k):
            print(n, '=', k, '+ 2 *', i, '^ 2')
            break
    else:
        print(n, ': NOT FOUND')
        return False
    return True
示例#7
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)
示例#8
0
def find_chains(p):
    # mylib.is_prime()
    out = []
    sp = str(p)
    search_digits = ['0', '1', '2']
    replace_digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    for i in range(len(search_digits)):
        sub_out = []
        if search_digits[i] in sp and i != p % 10:
            # print(i, 'found in', p)
            for j in range(len(replace_digits)):
                x = int(replace_digits[j].join(sp.split(search_digits[i])))
                if mylib.is_prime(x):
                    sub_out.append(x)
        if len(sub_out):
            out.append(sub_out)
    return out
示例#9
0
def solve():
    for a in range(0, 10):
        for b in range(a, 10):
            for c in range(b, 10):
                for d in range(c, 10):
                    if mylib.dividable(a + b + c + d, 3):
                        continue
                    s = [a, b, c, d]
                    m = [
                        y for y in [int(x) for x in mylib.mutate(s)]
                        if int(y) > 1000 and mylib.is_prime(y)
                    ]
                    if len(m) < 3:
                        continue
                    pr = extract_progression(m)
                    if len(pr):
                        print(''.join([str(x) for x in pr]))
    return True
示例#10
0
def findLongestAForB(b):
    low = -b
    aa = [x for x in range(low, 1000, 2)]
    d = 0
    n = 0
    c = 0
    aaaa = []
    while len(aa):
        aaa = []
        for a in aa:
            c = n * (n + a) + b
            #print(n, a, b, c)
            if c > 1 and mylib.is_prime(c):
                aaa.append(a)
        if len(aaa):
            aaaa = aaa
        aa = aaa
        n += 1
    return [n - 1, aaaa]
示例#11
0
def findLongestAForB(b):
    low = - b
    aa = [x for x in range( low, 1000, 2)]
    d = 0
    n = 0
    c = 0
    aaaa = []
    while len(aa):
        aaa = []
        for a in aa:
            c = n * (n + a) + b
            #print(n, a, b, c)
            if c > 1 and mylib.is_prime(c):
                aaa.append(a)
        if len(aaa):
            aaaa = aaa
        aa = aaa
        n += 1
    return [n-1, aaaa]
示例#12
0
def sum_all(a):
    y = len(a)
    i = y
    f = False
    while i:
        x = y - i
        if i % 2:
            r = range(1, x + 1)
        else:
            r = range(1)
        for j in r:
            b = a[j:j + i]
            s = sum(b)
            if mylib.is_prime(s):
                f = True
                print(s, b, i)
        if f:
            break
        i -= 1
    return True
示例#13
0
def sum_all(a):
    y = len(a)
    i = y
    f = False
    while i:
        x = y - i
        if i % 2:
            r = range(1, x + 1)
        else:
            r = range(1)
        for j in r:
            b = a[j:j + i]
            s = sum(b)
            if mylib.is_prime(s):
                f = True
                print(s, b, i)
        if f:
            break
        i -= 1
    return True
示例#14
0
# 10 - [1, 2, 5, 10] - No
# 11 - [1, 11] - No
# 12 - [1, 2, 3, 4, 6, 12] - No
# 13 - [1, 13] - No
# 14 - [1, 2, 7, 14] - Yes
# 15 - [1, 3, 5, 15] -

def get_number_of_composite_dividers(a):
    if a == 1:
        return 1
    n = 1
    for dd in mylib.gather_dividers(a):
        n *= len(dd) + 1
    return n


k = 1
for x in range(15, 10 ** 7, 2):
    if mylib.is_prime(x):
        continue
    c = get_number_of_composite_dividers(x - 1)
    d = get_number_of_composite_dividers(x)
    e = get_number_of_composite_dividers(x + 1)
    # print(x, c, d, e)
    if c == d:
        print(x - 1, x, d)
        k += 1
    if d == e:
        print(x, x + 1, d)
        k += 1
print(k)
示例#15
0
 def is_strong(self):
     return self.is_harshad and mylib.is_prime(self.n // len(str(self.n)))
示例#16
0
    for x in w_list:
        out *= x ** w_list[x]
    return out


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)
示例#17
0
 def is_strong(self):
     return self.is_harshad and mylib.is_prime(self.n // self.sum)
示例#18
0
 def test_comprehension(self):
     l = [1, 2, 3, 4, 5, 6]
     res = list((x * 2 for x in l if mylib.is_prime(x)))
     # <=>
     res = [x * 2 for x in l if mylib.is_prime(x)]
     self.assertEqual([4, 6, 10], res)
示例#19
0
 def test_infinite(self):
     res = (x * 2 for x in demo_yield.infinite() if mylib.is_prime(x))
     for i in res:
         print(i)
示例#20
0
	def test_is_prime(self):
		self.assertEqual(is_prime(3, [2]), True)
		self.assertEqual(is_prime(4, [2, 3]), False)
		self.assertEqual(is_prime(5, [2, 3]), True)
		with self.assertRaises(ValueError):
			is_prime(9, [2])
示例#21
0
 def test_filter_map(self):
     l = [1, 2, 3, 4, 5, 6]
     res = demo_yield.filter(lambda x: mylib.is_prime(x), l)
     res = demo_yield.map(lambda x: x * 2, res)
     self.assertEqual([4, 6, 10], list(res))
示例#22
0
    return res

def filter(fn, l: Iterable[int]):
    for nb in l:
        if fn(nb):
            yield nb

def map(fn, l: Iterable[int]):
    for nb in l:
        yield fn(nb)

def list(g: Generator):
    res = []
    for i in g:
        res.append(i)

def infinite():
    i = 0
    while True:
        yield i
        i += 1


if __name__ == '__main__':
    l = range(10000000000000000000000000000000000000000)
    res = filter(lambda x: mylib.is_prime(x), l)
    res = filter(lambda x: x % 2 == 0, res)

    for i in res:
        print(i)
示例#23
0
 def gen_next_primes(self):
     return dict((y, True) for y in [self.n * 10 + x for x in (1, 3, 7, 9)] if mylib.is_prime(y))
示例#24
0
 def is_strong(self):
     return self.is_harshad and mylib.is_prime(self.n // self.sum)
示例#25
0
def solve():
    for a in range(0, 10):
        for b in range(a, 10):
            for c in range(b, 10):
                for d in range(c, 10):
                    if mylib.dividable(a + b + c + d, 3):
                        continue
                    s = [a, b, c, d]
                    m = [y for y in [int(x) for x in mylib.mutate(s)] if int(y) > 1000 and mylib.is_prime(y)]
                    if len(m) < 3:
                        continue
                    pr = extract_progression(m)
                    if len(pr):
                        print(''.join([str(x) for x in pr]))
    return True
示例#26
0
import mylib

myDigits = [1, 3, 5, 7, 9]

i = 0
complexPrimes = [
    [2, 3, 5, 7]
]
while len(complexPrimes[i]):
    newComplexPrimes = []

    for j in complexPrimes[i]:
        for k in myDigits:
            p = 10 * j + k
            if mylib.is_prime(p):
                newComplexPrimes.append(p)
    complexPrimes.append(newComplexPrimes)
    #print(newComplexPrimes)
    i+=1
s = 0
for pp in complexPrimes:
    for p in pp:
        if p < 10:
            continue
        q = int(str(p)[1:])
        while q:
            if not mylib.is_prime(q):
                break
            if q > 10:
                q = int(str(q)[1:])
            else:
示例#27
0
 def test_myfilter_dirty(self):
     l = [1, 2, 3, 4, 5, 6]
     res = demo_yield.myfilter_dirty(lambda x: x % 2 == 0, l)
     self.assertEqual([2, 4, 6], res)
     res = demo_yield.myfilter_dirty(lambda x: mylib.is_prime(x), l)
     self.assertEqual([2, 3, 5], res)
示例#28
0
 def gen_next_primes(self):
     return dict((y, True) for y in [self.n * 10 + x for x in (1, 3, 7, 9)]
                 if mylib.is_prime(y))
示例#29
0
 def test_generator(self):
     l = [1, 2, 3, 4, 5, 6]
     res = (x * 2 for x in l if mylib.is_prime(x))
     self.assertEqual([4, 6, 10], list(res))
示例#30
0
    for x in w_list:
        out *= x**w_list[x]
    return out


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)
示例#31
0
 def test_error(self):
     l = [1, 2, 3, 4, 5, 6]
     res = (x * 2 for x in l if mylib.is_prime(x))
     with self.assertRaises(Exception):
         _ = len(res)
示例#32
0
# 11 - [1, 11] - No
# 12 - [1, 2, 3, 4, 6, 12] - No
# 13 - [1, 13] - No
# 14 - [1, 2, 7, 14] - Yes
# 15 - [1, 3, 5, 15] -


def get_number_of_composite_dividers(a):
    if a == 1:
        return 1
    n = 1
    for dd in mylib.gather_dividers(a):
        n *= len(dd) + 1
    return n


k = 1
for x in range(15, 10**7, 2):
    if mylib.is_prime(x):
        continue
    c = get_number_of_composite_dividers(x - 1)
    d = get_number_of_composite_dividers(x)
    e = get_number_of_composite_dividers(x + 1)
    # print(x, c, d, e)
    if c == d:
        print(x - 1, x, d)
        k += 1
    if d == e:
        print(x, x + 1, d)
        k += 1
print(k)
示例#33
0
 def test_isprime(self):
     #AAA Act Arange Assert
     res = mylib.is_prime(7)
     self.assertTrue(res)
     res = mylib.is_prime(8)
     self.assertFalse(res)
示例#34
0
import mylib

myDigits = [1, 3, 5, 7, 9]

i = 0
complexPrimes = [[2, 3, 5, 7]]
while len(complexPrimes[i]):
    newComplexPrimes = []

    for j in complexPrimes[i]:
        for k in myDigits:
            p = 10 * j + k
            if mylib.is_prime(p):
                newComplexPrimes.append(p)
    complexPrimes.append(newComplexPrimes)
    #print(newComplexPrimes)
    i += 1
s = 0
for pp in complexPrimes:
    for p in pp:
        if p < 10:
            continue
        q = int(str(p)[1:])
        while q:
            if not mylib.is_prime(q):
                break
            if q > 10:
                q = int(str(q)[1:])
            else:
                q = 0
        else: