Cod sursa(job #1439374)
Utilizator | FMI Mares Medar Razvan Yusuke | Data | 22 mai 2015 10:56:23 |
---|---|---|---|
Problema | Ratphu | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Teme Pregatire ACM Unibuc 2014, Anul I, Semestrul 2 | Marime | 0.6 kb |
#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];
}