Pagini recente » Cod sursa (job #2330224) | Cod sursa (job #99069) | jc2015-runda2 | Cod sursa (job #2643684) | Cod sursa (job #466070)
Cod sursa(job #466070)
#include<cstring>
#include<fstream>
using namespace std;
#define c(i) (n[i] - '0')
char n[20];
long long p, np[1 << 18][20]; // numarul de posibilitati luand configuratia 'i', sa am restul 0
int main()
{
ifstream fin("ratphu.in");
ofstream fout("ratphu.out");
fin >> 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 + c(k)) % p] += np[i][j];
fout << np[(1 << s) - 1][0];
}