Skip to content

Instantly share code, notes, and snippets.

@FF256grhy
Last active June 4, 2021 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FF256grhy/979482ff66877f532b7fce36d73d1196 to your computer and use it in GitHub Desktop.
Save FF256grhy/979482ff66877f532b7fce36d73d1196 to your computer and use it in GitHub Desktop.
【競プロ典型 90 問】 005 - Restricted Digits(★7) https://atcoder.jp/contests/typical90/tasks/typical90_e
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define inc(i, n) for(int i = 0; i < (n); i++)
const int MOD = 1'000'000'007;
int b;
struct S {
vector<LL> v;
int w;
S(int ww) : v(b), w(ww % b) { }
friend void operator*=(S & x, S const & y) {
S ans(x.w * y.w);
inc(i, b) {
inc(j, b) {
(ans.v[(y.w * i + j) % b] += x.v[i] * y.v[j]) %= MOD;
}
}
x = ans;
}
};
LL ri() { LL a; cin >> a; return a; }
LL bit(LL n, LL i) { return (n >> i) & 1; }
int main() {
LL n = ri();
cin >> b;
S ans(1), ex(10);
ans.v[0] = 1;
{
int k = ri();
inc(i, k) { ex.v[ri() % b]++; }
}
inc(i, 60) {
if(bit(n, i) == 1) { ans *= ex; }
ex *= ex;
}
cout << ans.v[0] << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment