Pagini recente » Cod sursa (job #2760670) | Cod sursa (job #2944485) | Cod sursa (job #2707119) | Cod sursa (job #1282863) | Cod sursa (job #466077)
Cod sursa(job #466077)
#include<cstring>
#include<cstdio>
//using namespace std;
char n[20];
long long p, np[1 << 18][20]; // numarul de posibilitati luand configuratia 'i', sa am restul 0
int main()
{
freopen("ratphu.in", "r", stdin);
freopen("ratphu.out", "w", stdout);
scanf("%s %lld", &n, &p);
int s = strlen(n);
//PD
np[0][0] = 1;
for (int i = 0; i < (1 << s); ++i)
for (int j = 0; j < p; ++j)
if (np[i][j])
for (int k = 0; k < s; ++k)
if ((i & (1 << k)) == 0)
np[i | (1 << k)][(j * 10 + n[k] - '0') % p] += np[i][j];
printf("%lld", np[(1 << s) - 1][0]);
}