Пример #1
0
def rotate(n):
    powTen = int(10**(math.floor(math.log(n, 10))))
    rotations = []
    init = (n % powTen * 10 + n / powTen)
    rotations.append(init)
    while init != n:
        init = (init % powTen * 10 + init / powTen)
        rotations.append(init)

    return rotations


def getCircularPrimes(primeList):
    circularPrimes = [
        2,
        5,
    ]
    for p in primeList:
        rotations = rotate(p)
        if all(i % 2 == 1 and i % 5 != 0 for i in rotations):
            if all(i in primeList for i in rotations):
                for j in rotations:
                    circularPrimes.append(j)

    return circularPrimes


if __name__ == '__main__':
    circularPrimes = getCircularPrimes(tools.getPrimes(1000000))
    print len(set(circularPrimes))
Пример #2
0
    digits = []
    while powTen > 0:
        tmp = num / powTen
        digits.append(tmp)
        num %= powTen
        powTen /= 10

    return digits


def toNum(tup):
    return 1000 * tup[0] + 100 * tup[1] + 10 * tup[2] + tup[3]


if __name__ == '__main__':
    primes = sorted(tools.getPrimes(10000))
    primes = primes[168:]
    candidates = []
    done = []
    for prime in primes:
        prime_perms = []
        if prime in done:
            continue
        else:
            digits = getDigits(prime)
            for perm in itertools.permutations(digits):
                num = toNum(perm)
                if num in primes and num not in done:
                    prime_perms.append(num)
                    done.append(num)
Пример #3
0
#33491st
import math
import tools

def rotate(n):
	powTen = int(10**(math.floor(math.log(n, 10))))
	rotations = []
	init = (n%powTen*10 + n/powTen)
	rotations.append(init)
	while init != n:
		init = (init%powTen*10 + init/powTen)
		rotations.append(init)

	return rotations

def getCircularPrimes(primeList):
	circularPrimes = [2, 5,]
	for p in primeList:
		rotations = rotate(p)
		if all(i%2 == 1 and i%5 != 0 for i in rotations):
			if all(i in primeList for i in rotations):
				for j in rotations:
					circularPrimes.append(j)

	return circularPrimes

if __name__ == '__main__':
	circularPrimes = getCircularPrimes(tools.getPrimes(1000000))
	print len(set(circularPrimes))
Пример #4
0
def getDigits(num):
	powTen = 1000
	digits = []
	while powTen > 0:
		tmp = num/powTen
		digits.append(tmp)
		num %= powTen
		powTen /= 10

	return digits

def toNum(tup):
	return 1000*tup[0] + 100*tup[1] + 10*tup[2] + tup[3]

if __name__ == '__main__':
	primes = sorted(tools.getPrimes(10000))
	primes = primes[168:]
	candidates = []
	done = []
	for prime in primes:
		prime_perms = []
		if prime in done:
			continue
		else:
			digits = getDigits(prime)
			for perm in itertools.permutations(digits):
				num = toNum(perm)
				if num in primes and num not in done:
					prime_perms.append(num)
					done.append(num)
Пример #5
0
#32461st
import tools

prime_list = tools.getPrimes(100000)

def isPrime(x):
	index = 0
	while prime_list[index] <= x and index < len(prime_list):
		if prime_list[index] == x:
			return True
		index += 1
	return False

if __name__ == '__main__':
	max = 0
	coefficient_tuple = (0,0)
	for a in xrange(-999,1000,2):
		for b in xrange(-999,1000,2):
			if 1521 + b < a*39:
				break
			x = 0
			while isPrime(x**2 + a*x + b):
				x += 1
			if x > max:
				max = x
				coefficient_tuple = (a,b)

	print max
	print coefficient_tuple
	print coefficient_tuple[0] * coefficient_tuple[1]	
Пример #6
0
import math
import tools

primes = tools.getPrimes(800000)
primes.sort()

def is_prime(n):
	if n == 1:
		return False

	if n in primes:
		return True
	return False

def left_truncatable(n):
	while n > 0:
		if not is_prime(n):
			return False
		n /= 10
	return True

def right_truncatable(n):
	q = 10
	while q < n:
		if not is_prime(n%q):
			return False
		q *= 10
	return True

if __name__ == "__main__":
	start37 = primes[4:25]