Пример #1
0
#!/usr/bin/python
from primes_sieve import primes
from tools import isPandigital

# Tried with 987654321 but was too big.
# Went down until 7654321 and got the answer.
primes = primes(7652413)

for prime in primes[::-1]:
    if isPandigital(prime, 7):
        print prime
        break
Пример #2
0
#! /usr/bin/python
from primes_sieve import primes, isPrime

def truncate(n, direction):
  if len(str(n)) == 1 and isPrime(n):
    return True
  elif isPrime(n):
    if direction == 'LR':
      num = int(str(n)[1:])
    elif direction == 'RL':
      num = int(str(n)[:-1])
    return truncate(num, direction)
  return False

# Generate a primes list. This is a bad
# idea and could be optimized much more.
p = primes(800000)

# The [4:] removes the unwanted values
# of 2, 3, 5 and 7.
result = [i for i in p if truncate(i, 'LR') and truncate(i, 'RL')][4:]
print result
print sum(result)
Пример #3
0
#! /usr/bin/python
from primes_sieve import primes

primes = primes(9999)

# The next prime after 1487
primes = primes[primes.index(1493):]

for a in primes:
    b, c = a+3330, a+6660
    if b in primes and c in primes:
        a, b, c = str(a), str(b), str(c)
        if sorted(a) == sorted(b) == sorted(c):
            print '{0}{1}{2}'.format(a,b,c)
            break
Пример #4
0
#!/usr/bin/python
from primes_sieve import primes, isPrime
from time import time

start = time()
limit = 10**6
p = primes(limit)
prev_longest = 0


for i in xrange(0,len(p)):
    s, counter = 0, 0
    for num in p[i:]:
        s += num
        counter += 1
        if isPrime(s) and counter > prev_longest and s <= limit:
            prev_longest = counter
            print s, '| Terms:',counter
        elif s > limit: break

end = time()
print end-start
Пример #5
0
#!/usr/bin/python
from primes_sieve import primes
#####
# This problem needs a facelift.
# setting the bounds for the exponent and
# for the primes list is not efficient.
# A more efficient solution would implement a while
# loop until the smallest number is encountered.
#####
primes, exp = primes(6000), 40
goldbach = set(p + 2 * (i**2) for p in primes for i in xrange(1, exp))
nonprimes = [n for n in xrange(1, primes[-1]) if n not in primes]

result = set()
for n in nonprimes:
    for j in xrange(1, exp):
        x = n + 2 * (j**2)
        if x not in goldbach and x not in primes and x % 2 != 0:
            result.add(x)
print min(result)
Пример #6
0
#! /usr/bin/env python
from primes_sieve import primes

#The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

#Find the sum of all the primes below two million.
c = 0
for i in primes(2000000):
	c += i
print c
Пример #7
0
#! /usr/bin/env python
from primes_sieve import primes

#The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

#Find the sum of all the primes below two million.
c = 0
for i in primes(2000000):
    c += i
print c
Пример #8
0
#! /usr/bin/env python
from primes_sieve import primes

print primes(105000)[10000]
Пример #9
0
#!/usr/bin/python
from primes_sieve import primes

#####
# This problem needs a facelift.
# setting the bounds for the exponent and
# for the primes list is not efficient.
# A more efficient solution would implement a while
# loop until the smallest number is encountered.
#####
primes, exp = primes(6000), 40
goldbach = set(p + 2 * (i ** 2) for p in primes for i in xrange(1, exp))
nonprimes = [n for n in xrange(1, primes[-1]) if n not in primes]

result = set()
for n in nonprimes:
    for j in xrange(1, exp):
        x = n + 2 * (j ** 2)
        if x not in goldbach and x not in primes and x % 2 != 0:
            result.add(x)
print min(result)
Пример #10
0
#! /usr/bin/python
from primes_sieve import primes

p = primes(100)
pointer = 0
d = []

for i in p:
	if sum(p[:pointer]) in p:
		d.append(sum(p[:pointer]))
		print p[:pointer],sum(p[:pointer])
	pointer += 1

print d
Пример #11
0
#! /usr/bin/python
from primes_sieve import primes, isPrime


def truncate(n, direction):
    if len(str(n)) == 1 and isPrime(n):
        return True
    elif isPrime(n):
        if direction == 'LR':
            num = int(str(n)[1:])
        elif direction == 'RL':
            num = int(str(n)[:-1])
        return truncate(num, direction)
    return False


# Generate a primes list. This is a bad
# idea and could be optimized much more.
p = primes(800000)

# The [4:] removes the unwanted values
# of 2, 3, 5 and 7.
result = [i for i in p if truncate(i, 'LR') and truncate(i, 'RL')][4:]
print result
print sum(result)