Cod sursa(job #735710)

Utilizator robertpoeRobert Poenaru robertpoe Data 17 aprilie 2012 10:04:48
Problema Ratphu Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include<fstream>
#define x (1<<t)
#define y (1<<tt)
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
long long n,MAT[300000][23];
int p;
int A[23],i,j,k,t,tt;
int main()
{
	f>>n>>p;
	for(;n;n/=10)
		A[t++]=n%10;
	MAT[0][0]=1;
	for(i=1;i<x;i++) 
		for(j=0;j<p;j++)  
			for(tt=0;tt<t;tt++)
				if(i&y)
					MAT[i][(j*10+A[tt])%p]+=MAT[i-y][j];
	g<<MAT[x-1][0];
	return 0;
}