#!/usr/bin/python import eulerlib primes = eulerlib.sieveOfEratosthenes( int( 1e6 ) ) truncatablePrimes = [] for prime in primes: if eulerlib.isTruncatable( prime, primes ) and prime not in [2, 3, 5, 7]: truncatablePrimes.append( prime ) if len( truncatablePrimes ) == 11: break print sum( truncatablePrimes )
#!/usr/bin/python from eulerlib import sieveOfEratosthenes from eulerlib import howManyPrimes n = 1000 print "for n = 1000, n^2 = ", n ** 2 p = sieveOfEratosthenes(n) print "for p = ", len(p), ", p^2 = ", len(p) ** 2 p.reverse() p.append(1) maxPrime = 0 aMax = 0 bMax = 0 for ii in p: for kk in p: howMany1 = howManyPrimes(ii, kk) howMany2 = howManyPrimes(-ii, kk) howMany3 = howManyPrimes(ii, -kk) howMany4 = howManyPrimes(-ii, -kk) howManyMax = max([howMany1, howMany2, howMany3, howMany4]) if howManyMax > maxPrime: maxPrime = howManyMax aMax = ii bMax = kk print maxPrime, ', ', aMax, ', ', bMax, ', ', aMax, ', ', bMax
#!/usr/bin/python import eulerlib if __name__ == '__main__': ''' http://mathworld.wolfram.com/DecimalExpansion.html http://en.wikipedia.org/wiki/Repeating_decimal http://mathworld.wolfram.com/DiscreteLogarithm.html http://en.wikipedia.org/wiki/Discrete_logarithm ''' dMax = 1000 primes = eulerlib.sieveOfEratosthenes(dMax) primes.remove(2) primes.remove(5) primes.reverse() kMax = 1 pMax = primes[0] for p in primes: k = 1 while (pow(10, k) % p) != 1: k += 1 if k > kMax: kMax = k pMax = p print 'Repeating length: ', kMax
#!/usr/bin/python from eulerlib import sieveOfEratosthenes from eulerlib import rotateInt from eulerlib import nDigits primes = sieveOfEratosthenes(1000000) #primes = sieveOfEratosthenes(100) ncircPrimes = 0 digits = [[], [], [], [], [], []] for ii in primes: n = nDigits( ii ) digits[n - 1].append( ii ) for n in range(len(digits)): # Loop over each bucket print n for m in digits[n]: # Loop over the integers in each bucket isCircPrime = True for l in range(n + 1): # Loop over the rotations of each number if rotateInt(m, l) not in digits[n]: break else: ncircPrimes = ncircPrimes + 1 print ncircPrimes