inlinelonglongsolve(longlong k){ int n = 0; std::vector<int> bit = { 0 }; for (; k; k /= 10, n++) bit.push_back(k % 10); std::reverse(bit.begin() + 1, bit.end());
staticlonglong f[MAXN][9 * MAXN][9 * MAXN][2]; longlong ans = 0;
for (int sum = 1; sum <= n * 9; sum++) { memset(f, 0, sizeof(f)); f[0][0][0][1] = 1;
for (int i = 0; i < n; i++) { for (int s = 0; s <= sum; s++) { for (int m = 0; m < sum; m++) { for (int c = 0; c <= 1; c++) { if (f[i][s][m][c]) { for (int k = 0; k <= (c ? bit[i + 1] : 9); k++) { if (s + k > sum) break; f[i + 1][s + k][(m * 10 + k) % sum][c && (k == bit[i + 1])] += f[i][s][m][c]; } } } } } }