0

I need a function, that counts qubic sqrt from numbers like "870173066968320732544446496734480471196048093882940477135564528632551009465406601739604153741989544040285198729843828711857728675712762181085236207667545603536162842302175366546276103838495195796306608106256008929381593162741660614088613949421430369141326922338669148063540060265033229672307675570376546971782846390748375563378238862483224396519406443628994007296206010036326446773204523330346859939124599677552660692846099285335643409874443114859854775486618744734879549182394454503065478103893936293242615167688821739282253380579469272516457310736517597519995474780006723467823548020725553053243518041561497600"

Unfortunaly, standart functions like num ** (1/3) or evem math.sqrt can do it only with little numbers. Im getting overflow errors when try to use it. When i work with Decimal() - i'm getting some issues with accuracy of root. So, maybe i do something wrong? How to get the easy-root with python?

Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
Goldus
  • 109
  • 2
  • 6
  • 1
    "When i work with Decimal() - i'm getting some issues with accuracy of root" how are you using `Decimal` ? is the duplicate answering your question? – Jean-François Fabre Feb 24 '21 at 22:18
  • Python can handle very large integers, but not very large floats. You need to solve this using integers only. Using 1/3 forces a float solution. This is easily solvable using Newton's method. Iterate using only multiplication and subtraction and you'll get the answer. – ohtotasche Feb 24 '21 at 22:26
  • 1
    Here's an easy to implement algorithm: https://www.geeksforgeeks.org/find-cubic-root-of-a-number/ – ohtotasche Feb 24 '21 at 22:27
  • 1
    The linked duplicate deals with square root rather than cube root. The code in this answer might help for cube root: https://stackoverflow.com/a/35276426/270986 – Mark Dickinson Feb 25 '21 at 08:28

0 Answers0