Cod sursa(job #2031890)
Utilizator | Data | 3 octombrie 2017 22:58:47 | |
---|---|---|---|
Problema | Ratphu | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.65 kb |
#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;
}