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.
- Recursive Digit Sum
- Discussions
Recursive Digit Sum
Recursive Digit Sum
Sort by
recency
|
606 Discussions
|
Please Login in order to post a comment
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
If you're having trouble with timeouts or the last 3 cases:
len(n) * k
length or try to implement a loop over the string repeatedly - just calculate the sum of the digits ofn
then multiply by kin java int isn't big enough have to use a bigger data type for the sum
148, 3
1+4+8 = 13 1+3 = 4 4+0 = 4
Wrong Result = 4 Correct Result = 3
Bug