Cod sursa(job #1439373)
| Utilizator | Data | 22 mai 2015 10:55:26 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Teme Pregatire ACM Unibuc 2014, Anul I, Semestrul 2 | Marime | 0.62 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 ][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];
}
