Example #1
0
def isTruncatable(num):
    if not mathlib.isPrime(num):
        return False

    num_str = str(num)
    length = len(num_str)
    for i in range(1, length):
        if not mathlib.isPrime(int(num_str[0:i])):
            return False
        
    for i in range(1, length):
        if not mathlib.isPrime(int(num_str[i:length+1])):
            return False

    return True
Example #2
0
def solve():
    digits = [str(x) for x in range(1, 10)]
    while len(digits) > 1:
        seq = copy.deepcopy(digits)
        pandigitals = [int(x) for x in mathlib.permute(seq)]
                       #if int(x[len(digits)-1]) % 2 != 0 and x[len(digits)-1] != '5']

        # we do some optimization here, to filter the element could be divid by
        # any number in range 2 to 9
        optimization = []
        for item in pandigitals:
            op = True
            for i in range(2, 10):
                if item % i == 0:
                    op = False
                    break
                else:
                    pass
            if op == True:
                optimization.append(item)
        optimization.sort()
        digits.pop()
        
        for i in range(len(optimization)-1, -1, -1):
            if mathlib.isPrime(optimization[i]):
                return optimization[i]
        
    return ''
Example #3
0
def solve():
    init, dias, primes, max_dias = 7, 13, 8, 49
    while True:
        ratio = primes / float(dias)
        if ratio <= 0.1:
            break
        init += 2
        for i in range(4):
            max_dias += (init-1)
            if mathlib.isPrime(max_dias):
                primes += 1
            dias += 1
    return init
Example #4
0
def solve():
    primes = mathlib.getPrimes(1000000)
    primesum = [0]
    s = 0
    count = 0
    while s < 1000000:
        s += primes[count]
        primesum.append(s)
        count += 1
    terms = 1
    for i in range(count):
        for j in range(i + terms, count):
            n = primesum[j] - primesum[i]
            if (j-i>terms and mathlib.isPrime(n)):
                terms, maxprime = j-i, n
    return maxprime