On Jan 31, 5:43 am, "Tim Roberts" <t.robe...@cqu.edu.au> wrote: > Dan, > > Thanks - you're probably right - just my intuition said to me that rather > than calculating that the 13th root of > 4021503534212915433093809093996098953996019232 > is 3221.2904208350265.... > there must be a quicker way of finding out its between 3221 and 3222.... > > ....but perhaps not.
I don't think you'll find anything much quicker than n**(1./13) (though I hope that if you're doing this millions of time then you're precomputing the 1./13 rather than redoing the division every single time. What happens behind the scenes here is that your integer is immediately converted to a float, then the system math library is used for the power operation. The integer -> float conversion is probably quite significant, timewise. I'd also be a bit worried about accuracy. Is it important to you that the integer part of the result is *exactly* right, or is it okay if (n**13)**(1./13) sometimes comes out as slightly less than n, or if (n**13-1)**(1./13) sometimes comes out as n? Mark -- http://mail.python.org/mailman/listinfo/python-list