예제 #1
0
def right_truncs():
    ans = [2, 3, 5, 7]
    l = 0
    changed = True
    while changed:
        l += 1
        changed = False
        work_seq = [s for s in ans if math.floor(math.log10(s)) == l - 1]
        for s in work_seq:
            for x in (1, 3, 7, 9):
                n = 10 * s + x
                if is_prime(n):                    
                    ans.append(n)
                    changed = True
    
    return {s for s in ans if s > 10}
예제 #2
0
def main():
    p = 0
    for i, d in enumerate(diags()):
        p += len([n for n in d if intlib.is_prime(n)])
        r = p/(5+4*i)
        if r < 0.1: return 2*i + 3
예제 #3
0
def is_left_truncatable(n):
    s = str(n)
    while s:
        if not is_prime(int(s)): return False
        s = s[1:]
    return True
예제 #4
0
def is_right_truncatable(n):
    while n > 0:
        if not is_prime(n): return False
        n = n // 10
    return True
예제 #5
0
if __name__ == '__main__':
    '''
    4<= n <=9 を探索すれば良い.
    1+2+3+4+5 = 15 より, 5ケタのpandigital numberは3の倍数
    となるから, 調べなくて良い.
    1+2+3+4+5+6 = 21
   1 + ... + 8 = 36
   1 + ... + 9 = 45  
    より6, 8, 9ケタも同様に対象外.
    7ケタのうち, 末尾が3,7の数を調べれば良い.
    '''
    
    max_prime = 2143
    for n in itertools.permutations('1234'):
        n = int(''.join(n))
        if intlib.is_prime(n):
            max_prime = max((n, max_prime))
    
    for n in itertools.permutations('124567'):
        n = int(''.join(n) + '3')
        if intlib.is_prime(n):
            max_prime = max((n, max_prime))
            
    for n in itertools.permutations('123456'):
        n = int(''.join(n) + '7')
        if intlib.is_prime(n):
            max_prime = max((n, max_prime))
    
    print(max_prime)