Cod sursa(job #1225473)
Utilizator | Data | 2 septembrie 2014 17:08:03 | |
---|---|---|---|
Problema | Ratphu | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXL = 20;
const int MAX = 262144;
char v[MAXL];
int p, n;
long long c[MAX][MAXL];
int main() {
freopen("ratphu.in", "r", stdin);
freopen("ratphu.out", "w", stdout);
scanf("%s %d", v, &p);
n = strlen(v);
c[0][0] = 1;
for (int i = 0; i < 1<<n; ++i)
for (int j = 0; j < p; ++j)
for (int k = 0; k < n; ++k)
if ((i&(1<<k)) == 0)
c[i^(1<<k)][(j*10+v[k]-'0')%p] += c[i][j];
printf("%lld\n", c[(1<<n)-1][0]);
return 0;
}