Last active
March 26, 2017 08:42
-
-
Save SF-Zhou/fb3aafa74b6099067a515410afff55f9 to your computer and use it in GitHub Desktop.
2017 Netease Distribute Biscuit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <cstdio> | |
#include <cstring> | |
#include <vector> | |
#include <queue> | |
#include <cmath> | |
#include <unordered_map> | |
using namespace std; | |
#define ff(i, n) for (int i = 0, END = (n); i < END; i ++) | |
#define fff(i, n, m) for (int i = (n), END = (m); i <= END; i ++) | |
#define dff(i, n, m) for (int i = (n), END = (m); i >= END; i --) | |
#define travel(e, first) for (int e = first, v = vv[first]; ~e; e = nxt[e], v = vv[e]) | |
#define clr(a, b) memset(a, b, sizeof(a)) | |
typedef long long ll; | |
int main() { | |
int n; | |
string in; | |
while (cin >> in >> n) { | |
unordered_map<int, ll> store[2]; | |
int now = 0, pre = 1; | |
store[now][0] = 1; | |
for (char ch: in) { | |
swap(now, pre); store[now].clear(); | |
ff (j, 10) { | |
if (isdigit(ch) && ch - '0' != j) continue; | |
for (auto it: store[pre]) { | |
store[now][(it.first * 10 + j) % n] += it.second; | |
} | |
} | |
} | |
cout << store[now][0] << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment