Example #1
0
def main():
    primes = getPrime(3, 10000)
    begin_time = time()
    prime_order, prime_pair = get_prime_pairs(primes)
    end_time = time()
    print "Time spend = %.3fs." % (end_time - begin_time)

    begin_time = time()
    for i in xrange(len(prime_order)):
        l = [prime_order[i]]
        candi = [x for x in prime_pair[prime_order[i]]]
        if try_one(l, candi, prime_pair, 5):
            end_time = time()
            print "Found:", l
            print "Sum:", sum(l)
            print "Time spend = %.3fs." % (end_time - begin_time)
            return
    end_time = time()
    print "Time spend = %.3fs." % (end_time - begin_time)
    print "Can not find such set. Add more primes."
    return
Example #2
0
#!/usr/bin/env python
# encoding=utf-8

import sys
import time
sys.path.append('..')
from utils.Prime import isPrime, getPrime
from utils.search import binarySearch

limit = 1000000L
result = 0
numberOfPrimes = 0L

primes = getPrime(1L,limit)

primeSum = [0]
for pm in primes:
  primeSum += [primeSum[-1]+pm]

start_time = time.time()
for i in xrange(numberOfPrimes,len(primeSum)):
  for j in xrange(i-(numberOfPrimes+1),-1,-1):
    d = primeSum[i] - primeSum[j]
    if d > limit: break
    if binarySearch(primes,d)>=0:
      numberOfPrimes = i - j
      result = d
      ri = i
      rj = j
end_time = time.time()
print 'Time elapsed:', end_time-start_time