Cod sursa(job #1439360)

Utilizator YusukeFMI Mares Medar Razvan Yusuke Data 22 mai 2015 10:38:32
Problema Ratphu Scor 30
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I, Semestrul 2 Marime 0.48 kb
#include<fstream>
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
long int N;
long long int M[300000][23];
int P, v[23], j, k, i, e;
int main()
{
    f >> N >> P;
    for (;N;N/=10)
        v[e++] = N%10;
    M[0][0] = 1;
    for(i = 1;i < (1<<e); i++)
        for(j = 0;j < P; j++)
            for(k = 0;k < e; k++)
                if( i & (1<<k))
                    M[i][(j*10 + v[k]) % P] += M[i - (1<<k)][j];
    g << M[(1 << e) - 1][0];
}