We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
However, if n is a very long number, int(n) may raise a ValueError due to the digit limit introduced in recent Python versions. You can bypass this by increasing the limit:
importsyssys.set_int_max_str_digits(100000)
Use with caution, especially when handling untrusted input, as increasing the limit can expose your code to denial-of-service risks.
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
You can solve this mathematically in Python with:
However, if
n
is a very long number,int(n)
may raise aValueError
due to the digit limit introduced in recent Python versions. You can bypass this by increasing the limit:Use with caution, especially when handling untrusted input, as increasing the limit can expose your code to denial-of-service risks.
Reference: Python Docs – Integer string conversion length limitation