Cod sursa(job #1439365)
Utilizator | FMI Mares Medar Razvan Yusuke | Data | 22 mai 2015 10:41:59 |
---|---|---|---|
Problema | Ratphu | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Teme Pregatire ACM Unibuc 2014, Anul I, Semestrul 2 | Marime | 0.51 kb |
#include<cstdio>
using namespace std;
long long int N, M[300000][23];
int P, v[23], j, k, i, e;
int main()
{
freopen("ratphu.in","r",stdin);
freopen("ratphu.out","w",stdout);
scanf("%lld%lld", &N, &P);
for (;N;N/=10)
v[e++] = N%10;
M[0][0] = 1;
for(i = 1;i < (1<<e); i++)
for(j = 0;j < P; j++)
for(k = 0;k < e; k++)
if( i & (1<<k))
M[i][(j*10 + v[k]) % P] += M[i - (1<<k)][j];
printf("%lld", M[ (1<<e) - 1][0]);
}