TITLE: How many different numbers can be written if each used digit symbol is used at least 2 times?
QUESTION [18 upvotes]: How many different numbers can be written if each used digit symbol is used at least 2 times ?
I would like to find the function $P(n,d)$:
$P(n,d)$ where  $n$ is base, $d$ is digit; 
Some examples:
 $n=3$ , $d=3$;
$$(000)_3$$
$$(111)_3$$
$$(222)_3$$
$P(3,3)=3$

It is easy that we can generalize for 3 digit numbers that $P(n,3)=n$
$P(3,4)=3.\cfrac{4!}{4!}+\cfrac{3.2}{2!}.\cfrac{4!}{(2!)^2}=21$

$(0000)_3 , (1111)_3$ two examples for $3.\cfrac{4!}{4!}$
$(0011)_3 ,(1212)_3$  two examples for $\cfrac{3.2}{2!}.\cfrac{4!}{(2!)^2}$


$P(4,4)=4.\cfrac{4!}{4!}+\cfrac{4.3}{2!}\cfrac{4!}{2!.2!}=40$

$(0000)_4, (1111)_4$ two examples in $4.\cfrac{4!}{4!}$
$(0011)_4 ,(3232)_4 $  two examples in $\cfrac{4.3}{2!}\cfrac{4!}{2!.2!}$


$P(3,5)=3.\cfrac{5!}{5!}+3.2\cfrac{5!}{3!.2!}=63$

$(00000)_3 ,(22222)_3$ two examples in $3.\cfrac{5!}{5!}$
$(00110)_3 ,(02020)_3 $  two examples in $3.2\cfrac{5!}{3!.2!}$


$P(3,6)=3.\cfrac{6!}{6!}+\cfrac{3.2}{2!}\cfrac{6!}{3!.3!}+(3.2)\cfrac{6!}{2!.4!}+\cfrac{3.2.1}{3!}\cfrac{6!}{2!.2!.2!}=243$

$(000000)_3 , (222222)_3$  two examples in $3.\cfrac{6!}{6!}$
$(001101)_3 , (020220)_3$  two examples in $\cfrac{3.2}{2!}\cfrac{6!}{3!.3!}$
$(002200)_3 , (111122)_3$  two examples in $(3.2)\cfrac{6!}{2!.4!}$
$(112200)_3 , (102021)_3$  two examples in $\cfrac{3.2.1}{3!}\cfrac{6!}{2!.2!.2!}$


Thanks for helps
EDIT: (2/21/2016)
I have noticed my mistakes in my formulas above and I corrected . Thanks a lot for answers. 
During my research on $P(n,d)$ , I got a conjecture. Thus the question has been going into very interesting points. 
(I do not know if it is known conjecture or not? Please let me know if you heard it. If it is true, this can let us to generalize The Fermat's Little theorem for any positive number. )
Fermat's little theorem:
$n^{p}\equiv n \pmod {p}$ where $p$ is prime number; $n$ is positive integer and $\gcd(n,p)=1$.
My conjecture:
$$n^{d}\equiv P(n,d) \pmod {d}$$ 
where $d$ and $n$ are any positive integers.
The conjecture is true for the (7X7) table that @Markus Scheuer gave in his answer. All values in the table were tested with success. I need your contribution to test my conjecture for large numbers. I have not found any counter-example to disprove my conjecture yet.
Note that I have the conjecture without proof. 
How can the conjecture be proven?
I would like to share  some my results for $P(n,d)$ . Please let me know if any fault in my formulas below.
$$P(n,1)=0$$
$$P(n,2)=n$$
$$P(n,3)=n$$
$$P(n,4)=n+\cfrac{n(n-1)}{2!}\cfrac{4!}{2!2!}=3n^2-2n$$
$$P(n,5)=n+\cfrac{n(n-1)}{1!}\cfrac{5!}{2!3!}=10n^2-9n$$
$$P(n,6)=n+\cfrac{n(n-1)}{2!}\cfrac{6!}{3!3!}+\cfrac{n(n-1)}{1!}\cfrac{6!}{4!2!}+\cfrac{n(n-1)(n-2)}{3!}\cfrac{6!}{2!2!2!}$$
$$P(n,6)=n+25n(n-1)+15n(n-1)(n-2)=15n^3-20n^2+6n$$
$$P(n,7)=n+\cfrac{n(n-1)}{1!}\cfrac{7!}{4!3!}+\cfrac{n(n-1)}{1!}\cfrac{7!}{2!5!}+\cfrac{n(n-1)(n-2)}{2!}\cfrac{7!}{3!2!2!}$$
$$P(n,7)=n+56n(n-1)+105n(n-1)(n-2)$$
Note that those formulas  above satisfy the $(7x7)$  (n/d) table that @Markus Scheuer gave in his answer.
We can write more terms if we want.
$$P(n,8)=n+\cfrac{n(n-1)}{1!}\cfrac{8!}{2!6!}+\cfrac{n(n-1)}{1!}\cfrac{8!}{3!5!} +\cfrac{n(n-1)}{2!}\cfrac{8!}{4!4!}+\cfrac{n(n-1)(n-2)}{2!}\cfrac{8!}{2!2!4!}+\cfrac{n(n-1)(n-2)}{2!}\cfrac{8!}{2!3!3!}+\cfrac{n(n-1)(n-2)(n-3)}{4!}\cfrac{8!}{2!2!2!2!}$$
..
..
$$P(n,d)=n+\cfrac{n(n-1)}{1!}\cfrac{d!}{2!(d-2)!}+\cfrac{n(n-1)}{1!}\cfrac{d!}{3!(d-3)!} +\cfrac{n(n-1)}{1!}\cfrac{d!}{4!(d-4)!}+.....$$

$$n^{d}\equiv P(n,d) \pmod {d}$$ 
If we put the results on above in my conjecture , we can get:
$$n^{2}\equiv n \pmod {2}$$ 
$$n^{3}\equiv n \pmod {3}$$ 
$$n^{4}\equiv 3n^2-2n \pmod {4}$$ 
$$n^{5}\equiv 10n^2-9n\pmod {5}\equiv -9n\pmod {5}\equiv n\pmod {5}$$ 
$$n^{6}\equiv 15n^3-20n^2+6n \pmod {6} \equiv 3n^3-2n^2 \pmod {6}$$ 
$$n^{7}\equiv n+56n(n-1)+105n(n-1)(n-2) \pmod {7}\equiv n \pmod {7}$$ 
$$n^{8}\equiv n^2(n-2)^2 \pmod {8}$$ 
EDIT: (2/22/2016)
An observation:
$$(n+1)^{d}=\sum_{k=0}^{d}{d\choose k}\>n^k$$ 
$$(n+1)^{d}\equiv \sum_{k=0}^{d}{d\choose k}\>n^k \pmod {d}$$ 
If $n^{d}\equiv P(n,d) \pmod {d}$ true;
$$P(n+1,d)\equiv \sum_{k=0}^{d}{d\choose k}\>P(n,k) \pmod {d}$$ 
Because of ${d\choose d-1}=d$
$$P(n+1,d)\equiv P(n,d)+ \sum_{k=0}^{d-2}{d\choose k}\>P(n,k) \pmod {d}$$
This result is very similar result  with the recursion formula of @Christian Blatter wrote in his answer.
$$P(n+1,d)=P(n,d)+\sum_{k=0}^{d-2}{d\choose k}\>P(n,k)\qquad(d\geq2)$$
EDIT
I have tested my conjecture with big numbers.
According to the table in sequence A231797 (Thanks a lot to @MarkusScheuer for the link)
There is an output for big numbers Table of n, a(n) for n = 0..410 . I tested for $n=d=410$  
$P(410,410)$ is 990 digits integer, you can see in the table that I gave in the link above. 
I confirmed in an online calculator that my conjecture is still true for that big number. 
$$410^{410}\equiv 0 \pmod {410}$$
$$P(410,410)\equiv 0 \pmod {410}$$
$$410^{410}\equiv P(410,410) \pmod {410}$$
Note: I have not tested my conjecture with big numbers for the case that $d \neq n$ . I do not know a generating function for the case $d \neq n$ as we have for $d=n$ as Markus Scheuer informed in his answer. Any idea for generating function for $d \neq n$?
Generating function for $d = n$
\begin{align*}
P(n,n)=n![x^n]\left(e^x-x\right)^n\qquad\qquad n\geq 0
\end{align*}
Thanks for helps and contributions

EDIT (26/2/2016): I have posted a proof for my conjecture above. You can find it below as an answer. Please feel free to write comments on it.

$$n^{d}\equiv P(n,d) \pmod {d}$$ 
where $d$ and $n$ are any positive integers.
Many special thanks to @ChristianBlatter and @MarkusScheuer  for their contributions to prove it. Especially  Christian Blatter's recurrence formula for $P(n,d)$  is the key to prove the conjecture.  Thanks a lot for sharing his idea with us. 
I have not found a related link for that theorem in the internet. Could you please share reference books or links if you know it? 
Thanks a lot for your helps

REPLY [3 votes]: We can keep this simple. The  labeled species of sequences of $q$ sets
with at least two elements is given by
$$\mathfrak{S}_{=q}(\mathfrak{P}_{\ge 2}(\mathcal{Z})).$$
We get the admissible contributions to $P(n,d)$ by choosing $q$ values
from  the $n$  different  digits  and letting  the  first  set be  the
positions of  the smallest chosen  digit, the  next one of  the second
smallest and so on. This yields the species
$$\sum_{q=1}^n {n\choose q} 
\mathfrak{S}_{=q}(\mathfrak{P}_{\ge 2}(\mathcal{Z})).$$
Translating to generating functions we have
$$\sum_{q=1}^n {n\choose q} (\exp(z)-1-z)^q
= -1 + (\exp(z)-z)^n.$$
This finally yields the closed formula
$$d! [z^d] (\exp(z)-z)^n.$$
Writing this with Stirling numbers we get
$$d! [z^d] (\exp(z)-1+1-z)^n
= d! [z^d] \sum_{p=0}^n {n\choose p} (\exp(z)-1)^p (1-z)^{n-p}
\\ = d! \sum_{p=0}^n {n\choose p} 
\sum_{q=0}^d [z^q] (\exp(z)-1)^p [z^{d-q}] (1-z)^{n-p}
\\ = d! \sum_{p=0}^n {n\choose p} 
\sum_{q=0}^d \frac{p!}{q!} {q\brace n} (-1)^{d-q} {n-p\choose d-q}.$$