Beispiel #1
0
def make_pairs(N):
  """Makes a prime pairs graph.
  
  Args:
    N: Largest possible prime in the prime pairs graph.

  Returns:
    A dictionary. 
  """

  g = defaultdict(lambda: [])

  for i in range(3, N):
    if not utils.isPrime(i):
      continue
    for j in range(i+1, N+1):
      if not utils.isPrime(j):
        continue
      ij = int(str(i) + str(j))
      if not utils.isPrime(ij):
        continue
      ji = int(str(j) + str(i))
      if not utils.isPrime(ji):
        continue
      g[i].append(j)
      g[j].append(i)

  return g
def solve():
    p = 223
    condition = True
    l = getSubsets(len(str(p)))
    lastLength = len(str(p))
    while (condition):
        print(p)
        st = str(p)
        if (lastLength != len(str(p))):
            l = getSubsets(len(str(p)))
            lastLength = len(str(p))
        for i in l:
            count = 0
            z = []
            for j in range(0, 10):
                newSt = st
                for k in i:
                    newSt = newSt[:k] + str(j) + newSt[k+1:]
                num = int(newSt)
                if (num != 0 and math.floor(math.log(num, 10)) + 1 != len(newSt)):
                    continue
                if (u.isPrime(int(newSt))):
                    count = count + 1
                    z.append(newSt)
                if (j > 2 and count < j - 2):
                    break
                if (count == 8):
                    condition = False
                    print(p, z)
        p = u.nextPrime(p)
Beispiel #3
0
def solve():
    p = 223
    condition = True
    l = getSubsets(len(str(p)))
    lastLength = len(str(p))
    while (condition):
        print(p)
        st = str(p)
        if (lastLength != len(str(p))):
            l = getSubsets(len(str(p)))
            lastLength = len(str(p))
        for i in l:
            count = 0
            z = []
            for j in range(0, 10):
                newSt = st
                for k in i:
                    newSt = newSt[:k] + str(j) + newSt[k + 1:]
                num = int(newSt)
                if (num != 0
                        and math.floor(math.log(num, 10)) + 1 != len(newSt)):
                    continue
                if (u.isPrime(int(newSt))):
                    count = count + 1
                    z.append(newSt)
                if (j > 2 and count < j - 2):
                    break
                if (count == 8):
                    condition = False
                    print(p, z)
        p = u.nextPrime(p)
def solve():
    for i in range(0, 9):
        l = getPandigitalList(i+1)
        for j in l:
            if (utils.isPrime(int(j))):
                print(j)
                break
        print(i)
Beispiel #5
0
def solve():
    for i in range(0, 9):
        l = getPandigitalList(i + 1)
        for j in l:
            if (utils.isPrime(int(j))):
                print(j)
                break
        print(i)
def solve():

    i = 1001
    while (i < 9999):
        if (p.isPrime(i)):
            ll = l.getListOfPermutations(str(i))
            diff = 0
            num = 0
            for n in ll:
                num = int(n)
                if (num != i and p.isPrime(num)):
                    diff = num - i
                    last = num + diff
                    try:
                        if (ll.index(str(last)) >= 0 and p.isPrime(last)):
                            print(i, num, last)
                    except ValueError:
                        continue
                    
        i = i + 2
Beispiel #7
0
def solve():

    i = 1001
    while (i < 9999):
        if (p.isPrime(i)):
            ll = l.getListOfPermutations(str(i))
            diff = 0
            num = 0
            for n in ll:
                num = int(n)
                if (num != i and p.isPrime(num)):
                    diff = num - i
                    last = num + diff
                    try:
                        if (ll.index(str(last)) >= 0 and p.isPrime(last)):
                            print(i, num, last)
                    except ValueError:
                        continue

        i = i + 2
Beispiel #8
0
def solve():
    count = 0
    for i in range (2, 1000000) :
        l = getListOfRotations(i)
        flag = True
        for n in l:
            if (not utils.isPrime(n)):
                flag = False
                break
        if (flag == True):
            count = count + 1
    return count
Beispiel #9
0
def solve():
    conjecture = True
    n = 9
    while (conjecture == True):
        conjecture = False
        while (utils.isPrime(n)):
            n = n + 2
        for i in range(2, n - 1):
            if (utils.isPrime(i)):
                twice = n - i
                j = 1
                difference = twice - 2 * j**2
                while (difference >= 0):
                    if (difference == 0):
                        conjecture = True
                        print(n, '=', i, '+2*', j, '^2')
                        break
                    j = j + 1
                    difference = twice - 2 * j**2
                if (conjecture == True):
                    break
        if (conjecture == False):
            return n
        n = n + 2
def solve():
    conjecture = True
    n = 9
    while (conjecture == True):
        conjecture = False
        while (utils.isPrime(n)):
            n = n + 2
        for i in range(2, n - 1):
            if (utils.isPrime(i)):
                twice = n - i
                j = 1
                difference = twice - 2*j**2
                while (difference >= 0):
                    if (difference == 0):
                        conjecture = True
                        print(n, '=', i, '+2*', j, '^2')
                        break
                    j = j + 1
                    difference = twice - 2*j**2
                if (conjecture == True):
                    break
        if (conjecture == False):
            return n
        n = n + 2
def solve():
    count = 1
    summ = 0
    i = 11
    while (count <= 11):
        l = getListOfTruncations(i)
        flag = True
        for n in l:
            if (not utils.isPrime(int(n))):
                flag = False
                break
        if (flag == True):
            summ = summ + i
            count = count + 1
        i = i + 1
    return summ
Beispiel #12
0
def solve():
    count = 1
    summ = 0
    i = 11
    while (count <= 11):
        l = getListOfTruncations(i)
        flag = True
        for n in l:
            if (not utils.isPrime(int(n))):
                flag = False
                break
        if (flag == True):
            summ = summ + i
            count = count + 1
        i = i + 1
    return summ
def solve():
    bestL = 0
    bestP = 0
    p = 2
    length = 2
    bound = 1000000
    while (p < bound): 
        s = 0
        last = p
        length = 2
        while (s < bound):
            s = s + last
            last = u.nextPrime(last)
            if (u.isPrime(s) and length > bestL):
                bestL = length
                bestP = s
                if (bestP > bound):
                    break
                else:
                    print(p, bestL, bestP)
            length = length + 1
        p = u.nextPrime(p)
        
    print(bestL, bestP)
Beispiel #14
0
def solve():
    bestL = 0
    bestP = 0
    p = 2
    length = 2
    bound = 1000000
    while (p < bound):
        s = 0
        last = p
        length = 2
        while (s < bound):
            s = s + last
            last = u.nextPrime(last)
            if (u.isPrime(s) and length > bestL):
                bestL = length
                bestP = s
                if (bestP > bound):
                    break
                else:
                    print(p, bestL, bestP)
            length = length + 1
        p = u.nextPrime(p)

    print(bestL, bestP)