Pagini recente » Cod sursa (job #1103356) | Cod sursa (job #1514193) | Cod sursa (job #1249249) | Cod sursa (job #788299) | Cod sursa (job #2031890)
#include <fstream>
using namespace std;
ifstream f ("ratphu.in");
ofstream g ("ratphu.out");
long long n, p, aux, w, nr;
short a[20], ap[20], st[100];
void perm(int k)
{
for (int x=1; x<=w; x++){
st[k]=a[x];
if (ap[x]==0){
ap[x]=1;
if (k==w){
aux=0;
for (int i=1; i<=w; i++) aux=aux*10+st[i];
if (aux%p==0) nr++;
}
else perm(k+1);
ap[x]=0;
}
}
}
int main ()
{
f >> n >> p;
while (n){
a[++w]=n%10;
n/=10;
}
perm(1);
g << nr << '\n';
return 0;
}