Cod sursa(job #473498)
| Utilizator | Data | 29 iulie 2010 20:00:14 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.47 kb |
#include<algorithm>
using namespace std;
char c[20];
int i,j,k,n,p;
long long rez[(1<<18)+2][20];
int main()
{
freopen("ratphu.in","r",stdin);
freopen("ratphu.out","w",stdout);
scanf("%s %d",c,&p);
for(i=0;'0'<=c[i]&&c[i]<='9';i++,n++)
c[i]-='0';
rez[0][0]=1;
for(i=0;i<(1<<n);i++)
for(k=0;k<n;k++)
for(j=0;j<p;j++)
if((i&(1<<k))==0)
rez[i+(1<<k)][(j*10+c[k])%p]+=rez[i][j];
printf("%lld\n",rez[(1<<n)-1][0]);
return 0;
}
