from time import time from atkins import atkins from eraosthenes import eraosthenes from zakiya import zak from sundaram import sundaram if __name__ == "__main__": k = int(input("Sieve algorithms.\nEnter an integer greater than 1. \n")) assert k > 1, "Enter an integer greater than 1!" start = time() zak(k) end = time() print("Sieve of Zakiya: " + str(end - start)) start = time() eraosthenes(k) end = time() print("Sieve of Eraosthenes: " + str(end - start)) start = time() sundaram(k) end = time() print("Sieve of Sundaram: " + str(end - start)) start = time() atkins(k) end = time() print("Sieve of Atkins: " + str(end - start))
#!/usr/bin/python # Filename: Problem007.py, projecteuler.net from atkins import atkins primeList = atkins(105000) print '10001st prime is {0}'.format(primeList[10000])
from atkins import atkins from listWorm import search maximi = 999999 counter = 0 circulars = 0 def hasEvenDigits(n): strNum = str(n) if '0' in strNum or '2' in strNum or '4' in strNum or '6' in strNum or '8' in strNum: return True else: return False #populate primeList primeList = atkins(maximi) while maximi > 1: if maximi == 2 or not hasEvenDigits(maximi): if search(maximi,primeList): iterator = 0 tested = maximi while iterator < len(str(maximi)): origStr = list(str(tested)) newStr = list(str(tested)) while len(origStr) < len(str(maximi)): origStr.insert(0, "0") newStr.insert(0, "0") counter = 0 while counter < len(str(maximi)): newStr[counter-1] = origStr[counter]
#!/usr/bin/python # Filename: Problem010.py, projecteuler.net. Sum of all primes under 2M from atkins import atkins sumOfPrimes = 0 primeList = atkins(2000000) for i in primeList: sumOfPrimes += i print('Sum of all primes smaller than 2Million = {0}'.format(sumOfPrimes))