Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int dp[200005][8];
- int main()
- {
- int n;
- cin >> n;
- string s;
- cin >> s;
- for(int i = 0; i <= n; i++) {
- for(int j = 0; j < 8; j++) {
- dp[i][j] = 0;
- }
- }
- dp[0][0] = 1;
- int MOD = 1e9 + 7;
- for(int i = 0; i < n; i++) {
- for(int remainder = 0; remainder < 8; remainder++) {
- dp[i + 1][remainder] += dp[i][remainder];
- dp[i + 1][remainder] %= MOD;
- dp[i + 1][(remainder * 10 + (s[i] - '0')) % 8] += dp[i][remainder];
- dp[i + 1][(remainder * 10 + (s[i] - '0')) % 8] %= MOD;
- }
- }
- cout << dp[n][0] - 1<< endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement