Pagini recente » Cod sursa (job #186652) | Cod sursa (job #2100128) | Cod sursa (job #98541) | Cod sursa (job #771064) | Cod sursa (job #1444191)
#include<fstream>
using namespace std;
const int NMAX = 20;
long long d[1 << NMAX][NMAX];
int c[NMAX];
long long n, p;
int l;
void solve(int x)
{
for (int i = 1; i < x; i++)
{
for (int j = 0; j < l; j++)
{
if (((1 << j) & (i)) == 0)
{
for (int k = 0; j < p; k++)
{
d[i | (1 << j)][(k * 10 + c[j]) % p] += d[i][k];
}
}
}
}
}
int main()
{
ifstream fin("ratphu.in");
ofstream fout("ratphu.out");
fin >> n >> p;
long long aux = n;
while (aux)
{
c[l] = aux % 10;
aux /= 10;
++d[(1 << l)][c[l] % p];
}
solve(1 << l);
fout << d[1<<l - 1][0];
}