The Square Root Dilemma
-----------------------------------
=> (A*B) is the a perfect square
For a given value of (A), we try to find all possible values of B which make A*B a perfect square.
A = OA * EA, where EA is the perfect square factor of A and OA is the other factor
So, (A*B) is perfect square when B can be factored as OA*(a perfect square).
def srm567(a,b):
ctr = 0
for i in range(1,a+1):
j = 2
s = 1
while (j*j)<= i:
if i%(j*j) == 0:
s = j*j
j += 1
r = i/s
#print "i,s:",i,s
y = 1
while (y*y*r)<=b:
ctr+= 1
y += 1
return ctr
-----------------------------------
=> (A*B) is the a perfect square
For a given value of (A), we try to find all possible values of B which make A*B a perfect square.
A = OA * EA, where EA is the perfect square factor of A and OA is the other factor
So, (A*B) is perfect square when B can be factored as OA*(a perfect square).
def srm567(a,b):
ctr = 0
for i in range(1,a+1):
j = 2
s = 1
while (j*j)<= i:
if i%(j*j) == 0:
s = j*j
j += 1
r = i/s
#print "i,s:",i,s
y = 1
while (y*y*r)<=b:
ctr+= 1
y += 1
return ctr
No comments:
Post a Comment