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
|
59 Discussions
|
Please Login in order to post a comment
According to the problem we can say the initial number has at most 10^5 digits. So the initial sum (not considering the repetition time should be at most 9 * 10^5 which can be stored in an 'int' variable. But the problem only can be solved when using 'long' for the sum variable.
There is a faster method creating a new recursive function that only works with numbers instead of string, but not sure if that was asked, because of how the question was structured.
Also, you can not even use recursion and just take (n*k)%9, but seems kinda magic
Python best solution
If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions
There is a faster method creating a new recursive function that only works with numbers instead of string, but not sure if that was asked, because of how the question was structured.
Also, you can not even use recursion and just take (n*k)%9, but seems kinda magic
Rust best solution
If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions
C#:
TypeScript