Cod sursa(job #1439386)
| Utilizator | Data | 22 mai 2015 11:19:07 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <fstream>
#include<iostream>
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
long long d[1<<19][21];
int cif[20],x,p;
int main()
{f>>x>>p;
int nr=0;
while(x)
cif[nr++]=x%10,x/=10;
d[0][0]=1;x=1<<nr;
for(int i=0;i<nr;i++)
d[1<<i][cif[i]%p]=1;
for(int i=1;i<x;i++)
for(int j=0;j<nr;j++)
{long u=1<<j;
if((i&u)==0)
for(int k=0;k<p;k++)
d[i+u][(k*10+cif[j])%p]+=d[i][k];
}
g<<d[x-1][0];
return 0;
}
