Cod sursa(job #3317114)

Utilizator robertcosacCosac Robert-Mihai robertcosac Data 22 octombrie 2025 11:15:21
Problema Ratphu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#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];
}