Number of substrings divisible by 8 but not 3

We need to find total number of substrings that are divisible by 8 but not 3 in the given string. For example, consider the string "356", this contains 1 substring that is divisible by 8 but not 3 i.e, 56, note that 3, 5, 6, 35, 356 aren't divisible by 8 and hence don't contribute towards the solution.



Before we start, recall:




A number x is said to be divisible by y is x % y == 0
A number is divisible by 3 if sum of its digit is divisible by 3
A number is divisible by 8 if its last three dig...
 •  0 comments  •  flag
Share on Twitter
Published on May 24, 2020 05:48
No comments have been added yet.