Beispiel #1
0
def isCircular(n):
    s = str(n)
    ns = map(lambda x: int(rotate(s, x)), range(1, len(s) + 1))
    for n in ns:
        if not isPrime(n):
            return False
    return True
Beispiel #2
0
def calc():
    corner = 1
    size = 2

    nonPrime = [1]
    prime = []
    i = 3

    while True:
        # loop through this layer
        for _ in range(4):
            corner += size
            if isPrime(corner):
                prime.append(corner)
            else:
                nonPrime.append(corner)
        # calculate new ratio
        corners = len(nonPrime) + len(prime)
        primes = len(prime)
        ratio = primes / corners
        print("i=", i, corners, primes, ratio)
        if ratio < 0.10:
            break
        size += 2
        i += 2
    return i
Beispiel #3
0
def problem357(n):
    divs = divisors(n)
    for d in divs:
        a = d + n // d
        if not isPrime(a):
            return False
    return True
Beispiel #4
0
def canConcat(ps):
    for a, b in permutations(ps, 2):
        if not isPrime(int(str(a) + str(b))):
            return False
        #else:
        #    print(a, b, str(a) + str(b))
    return True
Beispiel #5
0
def problem51():
    i = 0
    while True:
        i += 1
        if i % int(1e5) == 0:
            print(i)
        if not isPrime(i):
            continue
        ans = test(i)
        if ans != False:
            print(ans)
            break
Beispiel #6
0
def problem49():

    for n in range(1000, 10000):
        if not isPrime(n):
            continue
        for a in range(1000, 10000):
            ns = [n]
            total = n
            while len(ns) != 3:
                total = total + a
                if total > 9999:
                    break
                nextN = total
                if isPrime(nextN) and isPerm(n, nextN):
                    ns.append(nextN)
                else:
                    break
            if len(ns) == 3:
                print(ns)


# [1487, 4817, 8147]
# [2969, 6299, 9629]
# 0:00:16.765959 ELAPSED
Beispiel #7
0
def problem131():
    b = 1**3
    a = 2**3
    diff = a - b
    i = 3
    count = 0
    while diff < int(1e6):
        if isPrime(diff):
            count += 1
        b = a
        a = i**3
        i += 1
        diff = a - b
    print(count)

    return

    i = 2
    count = 0
    ratio = 0
    while True:
        cube = i * i * i
        i += 1
        #print(i)
        if ratio != 0:
            lowerBound = int(ratio * i)
        else:
            lowerBound = 1

        for n in range(lowerBound, i - 1):
            n3 = n * n * n
            n2 = n * n
            p = (cube - n3) // n2
            eq = n3 + n2 * p
            if eq == cube:
                if p in primes:
                    count += 1
                    ratio = n / i
                    print("i =", i, "n =", n, "p =", p, eq, "=", cube, count,
                          "below", i)
                    #print(cube - n3 == p * n2)
                    print("p + n", p + n, (p + n**(1.0 / 3.0)), "\n")
            #print(p, eq, eq == cube)
        if i >= limit:
            break
    print(count, "below", limit)
Beispiel #8
0
def problem387():
    primes = filter(isPrime, range(1, int(1e5)))
    bases = set()
    total = 0
    for p in primes:
        n = chop(p)
        if strongTrunc(n):
            print(p, str(p)[:2])
            bases.add(str(p)[:2])
            total += p
    #print(total)
    s = list(bases)
    s.sort()
    print(s, len(s))
    print(
        sum(
            filter(lambda x: strongTrunc(chop(x)) and isPrime(x),
                   range(1, int(1e4)))))
Beispiel #9
0
def isStrong(n):
    return isPrime(n / sum(map(int, str(n))))
Beispiel #10
0
def p(n):
    print(primeFactors(n))
    print(isPrime(n))