Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <queue>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- const int maxn = 2e5 + 10;
- const ll MOD = 1e9 + 7;
- int n;
- string s;
- ll dp[maxn][9];
- 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;
- return dp[at][remainder] = res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> s;
- memset(dp, -1, sizeof dp);
- cout << rec(0, 0) - 1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement