Pagini recente » Cod sursa (job #944993) | Cod sursa (job #858720) | Cod sursa (job #3126799) | Cod sursa (job #2262758) | Cod sursa (job #1439374)
#include<fstream>
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
#define MAXN 1 << 18
#define ll long long
int main()
{
ll int N, M[ MAXN ][23];
int P, v[23], e;
f >> N >> P;
for (;N;N /= 10){
v[e] = N % 10;
++M[(1 << e)][v[e++] % P];
}
int confmax = (1 << e);
for(int conf = 1; conf < confmax; ++conf)
for(int j = 0; j < e; ++j)
if(!((1 << j) & conf))
for(int r = 0; r < P; ++r)
M[conf | (1 << j)][(r * 10 + v[j]) % P] += M[conf][r];
g << M[confmax - 1][0];
}