Example #1
0
def foo():
    n = 3
    total_num = 5
    prime_num = 0

    while True:

        bottom_left = n**2 - n + 1
        upper_left = bottom_left - n + 1
        upper_right = upper_left - n + 1

        if is_prime(bottom_left):
            prime_num += 1

        if is_prime(upper_left):
            prime_num += 1

        if is_prime(upper_right):
            prime_num += 1

        if (prime_num * 1.0) / total_num < 0.1:
            break
        n += 2
        total_num += 4
    return n
Example #2
0
def foo():

    for n in reversed(range(1, 10)):
        digit_coll = reversed([str(i) for i in range(1, n+1)])
        for i in itertools.permutations(digit_coll, n):
            num = int(''.join(i))
            if is_prime(num):
                return num
Example #3
0
def foo():

    family_size = 8
    for num in (i for i in range(1000000)  if is_prime(i)):
        for sig in get_signiture(num):
            current_familiy_size = 0
            missed = 0
            first_prime_in_family = None

            for i in '0123456789':
                family_candidate = int(sig.replace('*', i))

                if len(str(family_candidate)) == len(sig) and is_prime(family_candidate):
                    current_familiy_size += 1
                    if first_prime_in_family is None:
                        first_prime_in_family = family_candidate
            if current_familiy_size == family_size:
                return first_prime_in_family
Example #4
0
def foo():
    n = 2

    while True:
        odd_num = 2 * n - 1
        if is_prime(odd_num):
            n += 1
            continue
        i = 1
        twice_a_square = 2 * (i ** 2)
        while odd_num > twice_a_square:
            if is_prime(odd_num - twice_a_square):
                break
            else:
                i += 1
                twice_a_square = 2 * (i ** 2)

        if odd_num <= twice_a_square:
            return odd_num
        else:
            n += 1
Example #5
0
def main():
    cache = {}
    max_ratio = 1
    n_max = 1000000

    max_val = 1
    for n in ( i for i in xrange(2, n_max+1) if is_prime(i) ):
        if max_val * n <= n_max:
            max_val *= n
        else:
            break

    print max_val
Example #6
0
def find_prime_factor_num(num):
    count = 0

    for i in prime_less_than_one_thousand:

        if is_prime(num) or num == 1:
            count += 1
            break

        if num % i == 0:
            count += 1
            while num % i == 0:
                num = num / i

    return count
Example #7
0
def foo():

    candidate_coll = []
    for i in range(1000, 10000):
        num = int(i)
        if is_prime(num):
            candidate_coll.append(num)

    candidate_set = set(candidate_coll)

    for i in range(len(candidate_coll)):
        for j in range(i+1, len(candidate_coll)):
            x, y = candidate_coll[i], candidate_coll[j]
            z = y + y - x
            if z in candidate_set and is_anagram([x, y, z]) and (x, y, z) != (1487, 4817, 8147):
                print x, y, z
                return ''.join([str(x), str(y), str(z)])
Example #8
0
def main():
    prime_less_than_ten_thousand = [i for i in range(2, 10000) if is_prime(i)]
    upper_bound = 50000000
    solution_coll = set()
    for x in prime_less_than_ten_thousand:
        x_square = x*x
        if x_square > upper_bound:
            break
        for y in prime_less_than_ten_thousand:
            y_cubic = y*y*y
            if y_cubic > upper_bound:
                break
            for z in prime_less_than_ten_thousand:
                z_fourth = (z*z)**2
                if z_fourth > upper_bound:
                    break
                val = x_square + y_cubic + z_fourth
                if val > upper_bound:
                    break
                solution_coll.add(x_square + y_cubic + z_fourth)

    print len(solution_coll)
Example #9
0
def foo():
    prime_less_than_thousand = [i for i in range(10000) if str(i)[-1] in '1379' and is_prime(i)]
    prime_table = {}
    print 'loaded'
    for i in prime_less_than_thousand:
        for j in prime_less_than_thousand:
            if i >= j:
                continue
            if is_prime_set((i, j)):
                prime_table[i] = prime_table.get(i, [])
                prime_table[i].append(j)

    min_val = -1
    print 'start'
    n = 5
    for key, val in prime_table.items():
        if len(val) >= n-1:
            for g in find_group(set(val), n-1, prime_table):
                print (key,) + g, key + sum(g)
                if min_val == -1 or min_val > key + sum(g):
                    min_val = key + sum(g)
    return min_val
Example #10
0
def infinite_prime_list():
    n = 2
    while True:
        if is_prime(n):
            yield n
        n += 1
Example #11
0
def is_prime_set(prime_set):
    for prime_pair in itertools.permutations(prime_set, 2):
        if not is_prime(int(str(prime_pair[0]) + str(prime_pair[1]))):
            return False
    return True
Example #12
0
    def enterPrime(self, ctx: JaRParser.PrimeContext):
        if prime.is_prime(self.stack.pop()):
            self.stack.push(True)

        else:
            self.stack.push(False)
Example #13
0
#! /usr/bin/python

from util.prime import is_prime

prime_less_than_one_thousand = [ i for i in range(1000) if is_prime(i)]

def find_prime_factor_num(num):
    count = 0

    for i in prime_less_than_one_thousand:

        if is_prime(num) or num == 1:
            count += 1
            break

        if num % i == 0:
            count += 1
            while num % i == 0:
                num = num / i

    return count

def foo():
    num = 600
    count = 0
    num_of_prime_factor = 4
    while True:

        if find_prime_factor_num(num) == num_of_prime_factor:
            count += 1
            if count == num_of_prime_factor: