Pagini recente » Cod sursa (job #1091565) | Istoria paginii utilizator/dargriga | Cod sursa (job #2158037) | Cod sursa (job #3313538) | Cod sursa (job #3317114)
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
long long dp[300002][20],v[25];
signed main()
{
int n, p;
f >> n >> p;
int k=0;
while (n)
{
v[++k]=n%10;
n/=10;
}
n=(1<<k)-1;
//cout<<n;
dp[0][0]=1;
for (int stare=0; stare<=n; stare++)
{
for (int rest=0; rest<p; rest++)
{
int copie=stare, put=1;
for (int l=1; l<=k; l++)
{
int x=copie%2;
copie/=2;
if (!x)
{
dp[stare+put][(rest*10+v[l])%p]+=dp[stare][rest];
}
put*=2;
}
}
}
g << dp[n][0];
}