''' Created on 2013-01-23 @author: paymahn ''' import CommonFunctions as cf import time t = time.time() primes = cf.generate_primes_less_than(100000) target_prime_factors = 4 target_consecutive = 4 consecutive = 0 result = 2*3*5*7 while consecutive < target_consecutive: result += 1 if(len(cf.find_prime_factors(result, primes)) >= target_prime_factors): consecutive+= 1 else: consecutive = 0 print "Done executing" print time.time() - t print result
''' Created on 2013-01-29 @author: paymahn ''' ''' Use Eulers totient function: http://www.math.okstate.edu/~wrightd/crypt/lecnotes/node18.html ''' import CommonFunctions as cf MAX = 10**6 totient = [0]*(MAX+1) primes = cf.sieve_of_Erastothenes(MAX) for i in range(2,MAX+1): factors = cf.find_prime_factors(i, primes) product = 1 for factor in factors: product *= factor**factors[factor] - factor**(factors[factor]-1) totient[i] = product print sum(totient) * 3/7