How to compute the nth root of a very big integer

后端 未结 10 634
暖寄归人
暖寄归人 2020-12-01 06:28

I need a way to compute the nth root of a long integer in Python.

I tried pow(m, 1.0/n), but it doesn\'t work:

OverflowError: lo

10条回答
  •  醉酒成梦
    2020-12-01 06:50

    Well, if you're not particularly worried about precision, you could convert it to a sting, chop off some digits, use the exponent function, and then multiply the result by the root of how much you chopped off.

    E.g. 32123 is about equal to 32 * 1000, the cubic root is about equak to cubic root of 32 * cubic root of 1000. The latter can be calculated by dividing the number of 0s by 3.

    This avoids the need for the use of extension modules.

提交回复
热议问题