Pagini recente » Cod sursa (job #3129247) | Cod sursa (job #232153) | Cod sursa (job #1729665) | Cod sursa (job #2982816) | Cod sursa (job #465958)
Cod sursa(job #465958)
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int elf[20];
int main ()
{
int i;
freopen("ratphu.in", "r", stdin);
freopen("ratphu.out", "w", stdout);
long long N,numar,rez=0;
int P;
vector<int> v;
scanf("%lld%d",&N,&P);
do
{
elf[++elf[0]]=N%10;
N/=10;
}
while(N);
for (i = 1; i <= elf[0]; ++i)
v.push_back(i);
do {
numar=0;
for(i=1;i<=elf[0];i++)
numar=numar*10+elf[v[i]];
if(numar%P==0)
rez++;
} while (next_permutation(v.begin(), v.end()));
printf("%lld",rez);
return 0;
}