On Wed, May 28, 2008 at 8:43 PM, Robert William Hanks <[EMAIL PROTECTED]> 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
Let's see. The inner loop will run 10000000 * 10000000 = 100000000000000 times. That's a pretty big number. Suppose each iteration of the loop takes 1 microsecond. (That seems optimistic but not too much - on my computer iscube(27) takes about 1.3 microseconds.) Then the entire program will complete in 10000000 * 10000000 / 1000000 / 60 / 60 / 24 / 365 = 3 years. Other than that it look OK to me... Looks like you need either a better algorithm or a faster computer! Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor