Ejemplo n.º 1
0
def do():
    for a in range(len(nnz)):
        for b in range(len(num)):
            for c in range(len(num)):
                for d in range(len(num)):
                    s = str(nnz[a]) + str(num[b]) + str(num[c]) + str(num[d])
                    if len(lex(s)) > 2:
                        for i in range(len(lex(s))):
                            for k in range(i + 2, len(lex(s))):
                                for j in range(i + 1, k):
                                    if is_prime(lex(s)[i]) and is_prime(
                                            lex(s)[j]) and is_prime(
                                                lex(s)[k]) and lex(s)[i] + lex(
                                                    s)[k] == 2 * lex(s)[j]:
                                        print(lex(s)[i], lex(s)[j], lex(s)[k])
                                        if 1487 not in [
                                                lex(s)[i],
                                                lex(s)[j],
                                                lex(s)[k]
                                        ]:
                                            print("Answer: " + "".join([
                                                str(lex(s)[i]),
                                                str(lex(s)[j]),
                                                str(lex(s)[k])
                                            ]))
                                            return
                    print(s)  # track
Ejemplo n.º 2
0
def pandipri(n):
    panpri = []

    num = []  # all 1-digit numbers from 1 to n
    int_num = []
    for i in range(n):
        num.append(str(i + 1))
        int_num.append(i + 1)

    perm = list(itertools.permutations(int_num))

    perm_list = []
    for i in range(len(perm)):
        joined = ''
        for j in range(n):
            joined += str(perm[i][j])
        perm_list.append(int(joined))

    for count in range(len(perm_list)):  # DUMMY COMMAND
        pan = 0
        for i in range(len(num)):
            if num[i] in list(str(perm_list[count])):
                pan += 1

        if pan == n and is_prime(perm_list[count]):
            panpri.append(perm_list[count])

    if panpri:
        print(f"{n} digits: {panpri[-1]}")
    else:
        print(f"{n} digits: No solution")
Ejemplo n.º 3
0
def hpf(n):
    result = 1  # some small number
    for i in range(n):
        if n % (i + 1) == 0 and is_prime(i + 1):
            result = i + 1
            print(result)  # track
    return result
Ejemplo n.º 4
0
from check_primes import is_prime

num = 11
count = 0
answer = 0

while count < 11:
    flag = True
    n1 = num
    n2 = num

    # truncatable from right to left
    for _ in range(len(str(num))):
        if is_prime(n1):
            n1 //= 10
        else:
            flag = False
            break

    # truncatable from left to right
    if flag:
        for i in range(len(str(num))):
            if is_prime(n2):
                n2 %= 10**(len(str(num))-i-1)
            else:
                flag = False
                break
        if flag:
            answer += num
            count += 1
            print(num)
Ejemplo n.º 5
0
from check_primes import is_prime

n = 1
answer = 2  # counted 2 as a prime number so we can skip it
while n < 2_000_000:
    if is_prime(n):
        answer += n
    n += 2
print(answer)
Ejemplo n.º 6
0
from number_theory import gcd
from check_primes import is_prime

q = 10**6
totient = lambda x: len(list(filter(lambda y: gcd(x, y) == 1, range(1, x))))
"""
ans = 0
n_ans = 0
for n in range(2,q+1):
    totient_value = totient(n)
    if n/totient_value > ans:
        ans = n/totient_value
        n_ans = n
"""

# You can run the above if you want, might take a lot of time.
# But think about this, what if we want to minimize totient(n)?
# Then we must as many prime factors as possible!
# So it's simply 2 x 3 x 5 x 7 x ... until it's still less then 1 million.

p = 0
result = 1
while result <= q:
    if is_prime(p):
        if result * p <= q:
            result *= p
        else:
            break
    p += 1
print(result)
Ejemplo n.º 7
0
    es = list(4 * (i + 1)**2 - 4 * (i + 1) + 1 for i in range(1, diag))
    ws = list(4 * (i + 1)**2 - 6 * (i + 1) + 3 for i in range(1, diag))
    nw = list(4 * (i + 1)**2 - 8 * (i + 1) + 5 for i in range(1, diag))
    result = [1] + ne + es + ws + nw
    return len(list(filter(is_prime, result))) / len(result) * 100


##i = 5
##while spiral2(i) >= 10:
##    i += 2
##    print(i)
##print('DONE',i)

prime = 8
numbers = 13
spiral = 7
while prime / numbers >= 0.1:
    #print(spiral)
    diag = (spiral + 1) // 2
    if is_prime(4 * (diag + 1)**2 - 10 * (diag + 1) + 7):
        prime += 1
    if is_prime(4 * (diag + 1)**2 - 8 * (diag + 1) + 5):
        prime += 1
    if is_prime(4 * (diag + 1)**2 - 6 * (diag + 1) + 3):
        prime += 1
    if is_prime(4 * (diag + 1)**2 - 4 * (diag + 1) + 1):
        prime += 1
    numbers += 4
    spiral += 2
print('DONE', spiral)
Ejemplo n.º 8
0
def concat_prime(n1,n2):
    concat1 = n1*10**(math.floor(math.log10(n2))+1)+n2
    concat2 = n2*10**(math.floor(math.log10(n1))+1)+n1
    return is_prime(concat1) and is_prime(concat2)
Ejemplo n.º 9
0
from check_primes import is_prime

answer = 1 # 2 is already included
passer = [0,2,4,5,6,8]

for count in range(3,10**6):
    if count < 10 and is_prime(count):
        answer += 1
        continue

    digits = list(map(int,str(count)))
    if False in list(filter(lambda x: x in passer, digits)):
        continue

    flag = True
    n = count
    for _ in range(len(digits)):
        if is_prime(n):
            n = (n//10)+(n%10)*(10**(len(digits)-1))
        else:
            flag = False
            break
    
    if flag:
        answer += 1

print(answer)