Robert William Hanks wrote:
Need ti find out whem a number o this form i**3+j**3+1 is acube.
 tryed a simple brute force code but, why this not work?
def iscube(n):
    cubed_root = n**(1/3.0)
    if round(cubed_root)**3 == n:
        return True
    else:
        return False

for i in range(1,10000000):
    for j in range(1,10000000):
         soma= i**3 +j**3 +1
         if isCube(soma):
             print i
             print j
             print soma

Assuming you fixed the problem, do you know of any cases for which i**3 +j**3 +1 is a cube?

Also note this program will run for a LONG time.

You can shorten the run time:

for i in range(1,10000000):
   for j in range(j,10000000): # test each combination once
        soma =  i**3 +j**3 +1
cubed_root = soma**(0.333) # function call and division take extra time and there is no need for either if abs(cubed_root - round(cubed_root)) < .01: # this is a guess at close enough, and cheaper than cubing?
            print i
            print j
            print soma

--
Bob Gailer
919-636-4239 Chapel Hill, NC

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to