Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- const int maxn = 200001;
- const ll MOD = 1e9 + 7;
- int n;
- string s;
- ll dp[maxn][8];
- ll rec(int at, int remainder) {
- if(at == n and remainder == 0) {
- return 1;
- }
- if(at == n) {
- return 0;
- }
- if(dp[at][remainder] != -1) {
- return dp[at][remainder];
- }
- ll res = 0;
- res += rec(at + 1, remainder);
- res %= MOD;
- int new_remainder = (remainder * 10 + (s[at] - '0')) % 8;
- res += rec(at + 1, new_remainder);
- res %= MOD;
- dp[at][remainder] = res;
- return res;
- }
- int main() {
- cin >> n;
- cin >> s;
- memset(dp, -1, sizeof dp);
- cout << rec(0, 0) - 1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment