#include #define ll long long #define inf 0x7fffffff #define ull unsigned long long #define llinf 0x7fffffffffffffff #define F(a,b,c,d) for(int b=c;b<=d;b+=a) #define F2(a,b,c,d) for(int b=c;b>=d;b-=a) #define PRC(b,a) fixed<>=1,xx=xx*xx%pp)yy&1?oo=oo*xx%pp:0;return oo;} inline void Cout(){cout< inline void Cout(T1 x,T2 ...y){cout<>w; for(int i=1;i<=8;++i) a[i]=i; do{ int p=0; for(int i=1;i<=8;++i) p=p*10+a[i]; ans+=(p%w==0); }while(next_permutation(a+1,a+9)); cout<