コード例 #1
0
	def getAnswer(self):
		
		n = 2
		while True:
			primes = [p for p in utility.getPrimes(pow(10, n))]
			
			for p in primes:
				if p < pow(10, n-1):
					continue
				
				for i in xrange(10):
					if str(p).count('%d' % (i)) == 0:
						continue
						
					count = 0
					for j in xrange(10):
						if int(str(p)[0]) == i and j == 0:
							continue
						q = int(str(p).replace('%d' % (i), '%d' % (j)))
						if p == q or utility.isPrime(q, primes):
							count += 1
					
					if count == 8:
						return p
			n += 1
コード例 #2
0
	def getAnswer(self):
		def isPermutations(p, q, r):
			p = str(p)
			q = str(q)
			r = str(r)
			for i in xrange(10):
				s = '%d' % i
				if p.count(s) != q.count(s) or q.count(s) != r.count(s):
					return False
			return True
		
		primes = utility.getPrimes(10000)
		for i in xrange(len(primes)):
			if primes[i] < 1000:
				continue
			for j in xrange(i + 1, len(primes)):
				p = primes[i]
				q = primes[j]
				r = q + q - p
				if r > 10000 or not utility.isPrime(r, primes):
					continue
				if not isPermutations(p, q, r):
					continue
				if p == 1487:
					continue
				return int(str(p) + str(q) + str(r))
		return -1
コード例 #3
0
	def getAnswer(self):
	
		primeLimit = 10000
		primes = utility.getPrimes(primeLimit)
		
		i = 0
		n = 1
		numPrime = 0
		numTotal = 1
		while True:
			i += 1
			
			for j in xrange(4):
				n = n + 2 * i
				
				if n >= primeLimit * primeLimit:
					primeLimit *= 2
					primes = utility.getPrimes(primeLimit)
					
				if utility.isPrime(n, primes):
					numPrime += 1
				numTotal += 1
			
			if numTotal > numPrime * 10:
				return i * 2 + 1
コード例 #4
0
		def f(limit):
			primes = utility.getPrimes(limit)
			length = 1
			ret = 0
			for i in xrange(len(primes)):
				for j in xrange(i + length, len(primes) - 1):
					s = sum(primes[i:j+1])
					if s >= limit:
						break
					if s < limit and utility.isPrime(s, primes):
						length = len(primes[i:j+1])
						ret = s
			return ret
コード例 #5
0
ファイル: euler35.py プロジェクト: yyl/euler-project-solution
from utility import isPrime, findPrime2

count = 0
for prime in findPrime2(1000000):
  prime = str(prime)
  for i in xrange(0, len(prime) - 1):
    if not isPrime(int(prime[i+1:] + prime[:i+1])):
      break
  else:
    count += 1
print count
コード例 #6
0
		def isPrime(n):
			return utility.isPrime(n, primes)
コード例 #7
0
		def isConcatenatedPrime(p, q, primes):
			return utility.isPrime(int(p + q), primes) and utility.isPrime(int(q + p), primes)