0
I am trying to understand the logic of the following code, but am not able to get the math behind it
The following code finds the count of substring that are divisible by number k given to the program of a string s. I am not able to understand the math that is working behind the algorithm used. Please help me with the actual logic behind the algorithm . Thanks in advance https://code.sololearn.com/cxu5FX7W7dWp/?ref=app
3 Answers
+ 3
Your code, converts the letters in a string to integer value one by one (with using stoi: string to integer function), then each letter becomes an integer. So, the letters divisible now and each letter divided by entered variable (k). Then result says how many letters divisible by the entered integer (k).
I hope, it is clear. Happy coding!
+ 3
Here is one of the better explanations as to how and why it works this way. Read it a couple of times. The code used is different and pseudocode, but the idea is the same.
https://stackoverflow.com/questions/35555910/efficiently-counting-the-number-of-substrings-of-a-digit-string-that-are-divisib
+ 2
Thanks mesarthim ChaoticDawg