Pagini recente » Cod sursa (job #180282) | Cod sursa (job #3249286) | Cod sursa (job #525229) | Cod sursa (job #1006276) | Cod sursa (job #1439373)
#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 ][19];
int P, v[19], e;
f >> N >> P;
ll AUX = N;
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];
}