Skip to content

Counting divisible Substrings #489

@PrashantVIT1

Description

@PrashantVIT1

Description

|| 8th Mar 2022 || HackWithInfy || Infosys ||

You are given a string Str of length N. Each character of the string is a base 10 digit.

Your task is to find the total number of substrings of Str such that the number denoted by the string Str[i...j] is divisible by 6. Since that result can be a very large return it is modulo 10^9+7.

Notes:
* It is given that a number denoted by Str[i..j] can have leading Zeroes.

Input Format
The first line contains an integer, N, denoting the length of the given string.
The next line contains a string, Str, denoting the given string.

Constrains
1 <= N <= 10^5
1 <= len(Str) <= 10^5

Sample Input Sample Output Explanation
3
328
0 No substring is divisible by 6
3
318
2 "18","318" divisible by 6
4
6151
1 "6" divisible by 6

Domain

Competitive Programming

Type of Contribution

Addition

Code of Conduct

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions