Pagini recente » Cod sursa (job #149126) | Cod sursa (job #1456312) | Cod sursa (job #2699842) | Cod sursa (job #1349665) | Cod sursa (job #1322438)
#include <cstdio>
using namespace std;
FILE *f,*g;
long long din[1<<18][20];
int main()
{
long long N;
int n,P,c[22];
f = fopen("ratphu.in","r");
g = fopen("ratphu.out","w");
fscanf(f,"%lld %d",&N,&P);
for (n=0 ; N>0 ; N/=10) {
c[n++] = N%10;
}
din[0][0]=1;
for (int i=0 ; i < (1<<n) ; ++i)
for (int r=0 ; r<P ; ++r)
if (din[i][r])
for (int j=0 ; j<n ; ++j)
if (!((1<<j)&i))
din[i+(1<<j)][(r*10 + c[j])%P]+=din[i][r];
fprintf(g,"%lld\n",din[(1<<n)-1][0]);
return 0;
}