Pagini recente » Cod sursa (job #2072860) | Cod sursa (job #663531) | Cod sursa (job #1223056) | Cod sursa (job #2176467) | Cod sursa (job #2021292)
#include <bits/stdc++.h>
const int MAXN = 18;
const int MAXP = 20;
int v[MAXN];
long long dp[1 << MAXN][MAXP];
int main() {
FILE *fi, *fout;
int i, p;
long long n;
fi = fopen("ratphu.in" ,"r");
fout = fopen("ratphu.out" ,"w");
fscanf(fi,"%lld %d " ,&n,&p);
int sz = 0;
while(n > 0) {
v[sz++] = n % 10;
n /= 10;
}
dp[0][0] = 1;
for(int conf = 1; conf < (1 << sz); conf++) {
for(i = 0; i < sz; i++)
if(conf & (1 << i)) {
for(int r = 0; r < p; r++)
dp[conf][(r * 10 + v[i]) % p] += dp[conf ^ (1 << i)][r];
}
}
fprintf(fout,"%lld" ,dp[(1 << sz) - 1][0]);
fclose(fi);
fclose(fout);
return 0;
}