Exemplo n.º 1
0
def is_trunc(num):

    for x in range(1, len(str(num))):
        if not is_prime(int(num[x:])) \
                or not is_prime(int(num[:x])):
            return False
    return True
Exemplo n.º 2
0
def prime_count(a, b):
    count = 0

    for n in range(b + 1):
        if is_prime(abs((n * n) + (a * n) + b)):
            count += 1
        else:
            break
    return count
Exemplo n.º 3
0
    def ok(a, p):
        """

        Args: two (alleged) primes
        Returns: whether the numbers (a)(p) (p)(a) (by concatenating a and p)
        are both primes or not
        """
        if a % 3 != p % 3:  # (a)(p) and (p)(a) mod 3 == (a) + (p)
            # as a and p primes, a and p !== 0 [3], and we do not want
            # the sum to be a multiple of 3.
            # problem if a or p == 3 ?!
            return False
        b = a * 10 ** len(str(p)) + p
        c = p * 10 ** len(str(a)) + a

        if b > 10 ** 7 and is_prime(b, l_7) or (b < 10 ** 7 and b in l_7_2):
            return c > 10 ** 7 and is_prime(c, l_7) or (c < 10 ** 7 and c in l_7_2)
        else:
            return False
Exemplo n.º 4
0
def problem_58():
    l_6 = numpy_sieve(10**6)
    nb, i = 0, 0
    a = 1
    while True:
        i += 1
        ii = i << 1
        a += ii << 2
        b = a - ii
        c = b - ii
        d = c - ii

        for j in [b, c, d]:
            if is_prime(j, l_6):
                nb += 1

        if nb * 10 <= (ii << 1):
            print(ii + 1)  # sol = 26241
            break
Exemplo n.º 5
0
def ok2(n):
    return is_prime(n // s_digit(n)) and (n != 1) and (n // s_digit(n) != 1)
Exemplo n.º 6
0
def ok(n):
    return n % s_digit(n) == 0


L = [i for i in range(1, 10)]
L_bis = [i for i in range(1, 10)]
for count in range(12):
    L_ter = []
    for a in L_bis:
        for i in range(10):
            b = a * 10 + i
            if ok(b):
                L_ter.append(b)
                L.append(b)
    L_bis = L_ter


def ok2(n):
    return is_prime(n // s_digit(n)) and (n != 1) and (n // s_digit(n) != 1)


L = [a for a in L if ok2(a)]

S = 0
for a in L:
    for i in [1, 3, 7, 9]:
        if is_prime(a * 10 + i):
            S += a * 10 + i

print("\n", S)
Exemplo n.º 7
0
from Tools import is_prime
from Tools import sieve_of_e


def rotate(num):
    chars = list(num)
    tmp = ""
    for x in range(1, len(chars)):
        tmp += chars[x]
    tmp += chars[0]
    return tmp


count = 0
primes = sieve_of_e(1000000)

for i in primes:
    check = i
    circular = True
    for x in range(len(str(check))):
        if not is_prime(int(check)):
            circular = False
            break
        else:
            check = rotate(str(check))
    if circular:
        count += 1

print(count)

Exemplo n.º 8
0
            for b in l_p:
                l_p2.append(b * l[i])
            f.append((i + 1, a, l_p2))
        else:
            s += p if ok_mieux(p, l_p) else 0

print(s)
print(time() - timer)

# %%% Problem 358

from Tools import is_prime

# we search for p prime such that (10**(p-1)-1)/p = 00000000137...56789
b = int(1 / 0.00000000137)
a = int(1 / 0.00000000138)
# a < p < b
k = 1
while (56789 * k) % 10**5 != 99999:
    k += 1
# p ends up with k
l = []
for p in range(a, b):
    if p % 10**5 == k and is_prime(p):
        l.append(p)

for a in l:
    print(9 * (a - 1) // 2)
# s is one of the values
# sol = 3284144505
Exemplo n.º 9
0
# %% Problem 245

# C(n) can not be an unit fraction if n = p^k * a with k > 1 and p prime

from Tools import is_prime, phi, decompose_tout


def unit_co_resilience(n):
    return (n - 1) % (n - phi(n)) == 0


s = 0
for i in range(2, 2 * 10**11 + 1):
    if not is_prime(i):
        if unit_co_resilience(i):
            s += i
            l = [b for a, b in decompose_tout(i)]
            if l.count(1) != len(l):
                print(i)