# # Using Heron's formula from Lubomir Markov's extension of Goehl's Method # M = [] from time import time st = time() for m in xrange(1, 1001): #print "m:",m, psum = 0 #u = 2*m fd0 = divisors(2 * m) # Factoring u = 2m for u in fd0: ul = u * 3**.5 # choosing factors up to u*sqrt(3) mxul = int(ul) + 1 for v in xrange(1, mxul): if gcd(u, v) != 1: continue # choosing v coprime to u f = 4 * m * m * (u * u + v * v) # = delta1 * delta2 fd = divisors(f) # obtaining factors for d1,d2 ul2 = int( 2 * m * ((u * u + v * v)**.5)) # obtaining sqrt to avoid repetitions #print "!",m,u,v # showing m,u,v for curiosity's sake for d1 in fd: if ((2 * m) * (v**2 - u**2) / u ) <= d1 <= ul2: #choosing range of delta1 to ensure A=mP if (d1 + 2 * m * u) % v: continue d2 = f / d1 if (d2 + 2 * m * u) % v: print "oooooooooooooops:", m, d1, d2, P continue a = (d1 + 2 * m * u) / v + (2 * m * v) / u
def notcoprime(cp, Y): for yy in Y: if gcd(yy, cp) != 1: return yy return -1
def notcoprime(cp,Y): for yy in Y: if gcd(yy,cp)!=1: return yy return -1
summ = 0 # # Using Heron's formula from Lubomir Markov's extension of Goehl's Method # M = [] for m in xrange(1, 1001): print "m:", m, psum = 0 # u = 2*m fd0 = divisors(2 * m) # Factoring u = 2m for u in fd0: ul = u * 3 ** 0.5 # choosing factors up to u*sqrt(3) mxul = int(ul) + 1 for v in xrange(1, mxul): if gcd(u, v) != 1: continue # choosing v coprime to u f = 4 * m * m * (u * u + v * v) # = delta1 * delta2 fd = divisors(f) # obtaining factors for d1,d2 ul2 = 2 * m * ((u * u + v * v) ** 0.5) # obtaining sqrt to avoid repetitions # print "!",m,u,v # showing m,u,v for curiosity's sake for d1 in fd: if ((2 * m) * (v ** 2 - u ** 2) / u) <= d1 <= ul2: # choosing range of delta1 to ensure A=mP d2 = f / d1 a = (d1 + 2 * m * u) / v + (2 * m * v) / u b = (d2 + 2 * m * u) / v + (2 * m * v) / u c = (d1 + d2 + 4 * m * u) / v A = ta(a, b, c) P = a + b + c R = A / float(P) # paranoid check to ensure ratios match if R == int(R): # Making sure Ratio is integer,probably not necessary
# # # Euler Problem 283 # # from Functions3 import GCD,gcd summ = 0 ctr,ctr1 = 0,0 for m in xrange(2, 4000): for n in xrange(1, m): if gcd(m,n)!=1 or (m-n)%2==0: continue a = (m*m - n*n) b = 2*m*n c = (m*m + n*n) #if GCD((a,b,c))>1:continue #print m,n,":",a,b,c #if a**2 +b**2 == c**2: A0=a*b/2;P0=a+b+c;R=float(A0)/P0 ctr+=1 #print m,n,":",a,b,c,":",A0,P0,R if R < 1001: #print a,b,c,":",A0,P0,R #summ += P0 i=1 while 1: A = A0*i**2 P = P0*i R = float(A)/P
# # # Euler Problem 283 # # from Functions3 import GCD, gcd summ = 0 ctr, ctr1 = 0, 0 for m in xrange(2, 4000): for n in xrange(1, m): if gcd(m, n) != 1 or (m - n) % 2 == 0: continue a = (m * m - n * n) b = 2 * m * n c = (m * m + n * n) #if GCD((a,b,c))>1:continue #print m,n,":",a,b,c #if a**2 +b**2 == c**2: A0 = a * b / 2 P0 = a + b + c R = float(A0) / P0 ctr += 1 #print m,n,":",a,b,c,":",A0,P0,R if R < 1001: #print a,b,c,":",A0,P0,R #summ += P0 i = 1 while 1: A = A0 * i**2
# # Using Heron's formula from Lubomir Markov's extension of Goehl's Method # #M=[] from time import time st = time() for m in xrange(1,1001): print "m:",m, psum = 0 # used to determine P sums for each m #u = 2*m fd0 = divisors(2*m) # Factoring u = 2m for u in fd0: ul = u*3**.5 # choosing factors up to u*sqrt(3) mxul = int(ul)+1 for v in xrange(1,mxul): if gcd(u,v)!=1:continue # choosing v coprime to u f = 4*m*m*(u*u +v*v) # = delta1 * delta2 fd = divisors(f) # obtaining factors for d1,d2 ul2 = int(2*m*((u*u+v*v)**.5)) # obtaining sqrt to avoid repetitions #print "!",m,u,v # showing m,u,v for curiosity's sake for d1 in fd: if ((2*m)*(v**2-u**2)/u)<= d1 <=ul2: #choosing range of delta1 to ensure A=mP if (d1+2*m*u)%v:continue d2 = f/d1 if (d2+2*m*u)%v:continue a = (d1+2*m*u)/v + (2*m*v)/u b = (d2+2*m*u)/v + (2*m*v)/u c = (d1+d2+4*m*u)/v #A = ta(a,b,c) P = a+b+c