def p073(N=12000): retval = 0 for d in range(2,N+1): total = p069.phi(d) lowerthird = len([n for n in range(d/3+1) if numty.gcd(n,d) == 1]) retval += total/2-lowerthird return retval
def uniques(N): table = [[] for n in range(N+1)] for k in range(1,N/12+1): for mplusn in range(3,int(math.sqrt(N/k))+1,2): for m in range(mplusn/2+1, mplusn): p = 2*k*m*mplusn if p > N: break if numty.gcd(m,mplusn) != 1: continue table[p].append((k,mplusn-m,m)) return [p for p in range(len(table)) if len(table[p]) == 1]
def uniques(N): table = [[] for n in range(N + 1)] for k in range(1, N / 12 + 1): for mplusn in range(3, int(math.sqrt(N / k)) + 1, 2): for m in range(mplusn / 2 + 1, mplusn): p = 2 * k * m * mplusn if p > N: break if numty.gcd(m, mplusn) != 1: continue table[p].append((k, mplusn - m, m)) return [p for p in range(len(table)) if len(table[p]) == 1]
def p127(N=120000): rad_table = radtable(N) a_table = sorted([(rad_table[a], a) for a in xrange(1, N)]) acc = 0 for c in xrange(N): lim = c / rad_table[c] for rad_a, a in a_table: if rad_a > lim: break if a >= (c + 1) / 2: continue if numty.gcd(rad_table[a], rad_table[c]) == 1: if rad_table[a] * rad_table[c - a] * rad_table[c] < c: logger.debug('%d %d %d' % (a, c - a, c)) acc += c return acc
def p127(N = 120000): rad_table = radtable(N) a_table = sorted([(rad_table[a], a) for a in xrange(1,N)]) acc = 0 for c in xrange(N): lim = c/rad_table[c] for rad_a, a in a_table: if rad_a > lim: break if a >= (c+1)/2: continue if numty.gcd(rad_table[a],rad_table[c]) == 1: if rad_table[a]*rad_table[c-a]*rad_table[c] < c: logger.debug('%d %d %d' % (a, c-a, c)) acc += c return acc
def lcm(a, b): return a * b / numty.gcd(a, b)
def lcm(a,b): return a*b/numty.gcd(a,b)