Beispiel #1
0
def main():
    global primeList
    n = 10000
    primeList = getPrimeList(n)
    i = 2
    while f(i, i-1) <= 5000:
        i += 1
        if i > primeList[-1]:
            n *= 10
            primeList = getPrimeList(n)
    print i
Beispiel #2
0
def find(n, minimal, index):
    p = getPrimeList(n)
    length = len(p)
    for a in range(index, length):
        if minimal and p[a] > minimal/5:
            return True, minimal, a
        for b in range(a+1, length):
            if not isConcatenatePrime(p[a], p[b]):
                continue
            for c in range(b+1, length):
                if (not isConcatenatePrime(p[a], p[c]) 
                        or not isConcatenatePrime(p[b], p[c])):
                    continue
                for d in range(c+1, length):
                    if (not isConcatenatePrime(p[a], p[d])
                            or not isConcatenatePrime(p[b], p[d])
                            or not isConcatenatePrime(p[c], p[d])):
                        continue
                    for e in range(d+1, length):
                        if (not isConcatenatePrime(p[a], p[e])
                                or not isConcatenatePrime(p[b], p[e])
                                or not isConcatenatePrime(p[c], p[e])
                                or not isConcatenatePrime(p[d], p[e])):
                            continue
                        if minimal and (p[a] + p[b] + p[c] + p[d] + p[e] >
                                minimal):
                            minimal = p[a] + p[b] + p[c] + p[d] + p[e]
                        break
    return False, minimal, length
Beispiel #3
0
def main():
    N = 50000000
    primelist = getPrimeList(N ** 0.5)
    square = []
    cube = []
    fourthpower = []
    for p in primelist:
        a = p*p
        if a >= N:
            break
        square.append(a)
        if a*p <= N:
            cube.append(a*p)
            if a*p*p <= N:
                fourthpower.append(a*p*p)
    count = []
    for c in fourthpower:
        for b in cube:
            if c+b >= N:
                break
            for a in square:
                if c+b+a >= N:
                    break
                count.append(c+b+a)
    print len(set(count))
Beispiel #4
0
def getPhi(n):
    primelist = getPrimeList(n)
    res = [i for i in range(2, n+1)]
    for i in range(len(primelist)):
        l = primelist[i]
        m = l
        while l <= n:
            res[l-2] *= (m-1)
            res[l-2] /= m
            l += m
    return res
Beispiel #5
0
def f(n):
    primeList = getPrimeList(n)
    subPrimeList = []
    length = 1
    tmpList = []
    for i in primeList:
        if len(str(i)) == length:
            tmpList.append(i)
        else:
            length += 1
            subPrimeList.append(tmpList)
            tmpList = [i]
    else:
        subPrimeList.append(tmpList)
    
    for subIndex in range(len(subPrimeList)):
        primeList = subPrimeList[subIndex]
        while len(primeList) >= 8:
            i = primeList[0]
            primeList.remove(i)
            strNum = str(i)
            for j in range(3):
                stro = str(j)
                tmpList = strNum.split(stro)
                length = len(tmpList)
                if length == 1:
                    continue
                for ii in range(2**(length-1)-1):
                    count = 1
                    count2 = 0
                    for k in range(j+1, 10):
                        strr = str(k)
                        rstr = ""
                        for jj in range(length-1):
                            if ((ii>>jj)&1) == 1:
                                rstr += tmpList[jj]+stro
                            else:
                                rstr += tmpList[jj]+strr
                        rnum = int(rstr + tmpList[-1])
                        if rnum not in primeList:
                            count2 += 1
                        else:
                            count += 1
                        if 10-8-j < count2:
                            break
                    if count == 8:
                        print i
                        return True
    return False
Beispiel #6
0
def main():
    t = getPrimeList(1000000)
    totallen = len(t)
    length = 0
    for i in range(totallen):
        if i+length >= totallen:
            break
        Sum = sum(t[i:i+length])
        for j in range(i+length, totallen):
            Sum += t[j]
            if Sum > 1000000:
                break
            if j-i+1 > length and isPrime(Sum):
                length = j-i+1
                Max = Sum
    print Max