def divisor_sigma_0(n): remain = n result = 1 primes = util.primes_upto(int(n/2+1)) i=0 curr_mult = 0 # multiplicity of the current prime while i < len(primes): curr_prime = primes[i] if remain%curr_prime==0: remain = remain/curr_prime curr_mult += 1 else: if curr_mult > 0: result *= curr_mult + 1 curr_mult = 0 i += 1 return result==1 and n!=1 and 2 or result
''' Created on Mar 22, 2009 @author: mturner ''' import util t = util.Timer() t.start() # take a guess that n won't be larger than 200 # so...generate primes less than 200**2 + 1000*200 + 1000 n_max_guess = 200 val_max_guess = n_max_guess**2 + 1000*n_max_guess + 1000 primes = util.primes_upto(val_max_guess) print "Found " + str(len(primes)) + " prime numbers." primes_table = [False for x in range(val_max_guess)] for i in primes: primes_table[i] = True print "Finished constructing primes table" max_pair = (0,0) max_n = 0 for a in range(-999,1000): for b in range(-999,1000): n = 0 while True: val = n**2 + a*n + b if val > val_max_guess: print "n_max_guess too small." break