How many surjective functions are there from $A=${$1,2,3,4,5$} to $B=${$1,2,3$}? I want to find how many surjective functions there are from the set $A=${$1,2,3,4,5$} to the set $B=${$1,2,3$}? I think the best option is to count all the functions ($3^5$) and then to subtract the non-surjective functions. However, I'm not sure how can I count these functions.
Thanks

Pedestrian approach:
How many surjective functions from:
$A$ ={ $1, 2, 3, 4, 5$} to $B$= {$a, b, c$} ?
1) Let $3$ distinct  elements of $A$ be mapped onto $a, b$, or $c$.
There are 
$\binom{5}{3} = 10$,
ways to pick $3$ elements from $5$.
There are $3$ ways to map these elements onto $a,b$, or $c$.
Altogether $3×10 = 30$ ways. 
Each choice leaves $2$ spots in $B$ empty; $2$ ways of filling the vacant spots with the $2$ remaining elements of $A$
Combining: $2×30 = 60$ ways of generating a surjectice map with $3$ elements mapped onto $1$  element of $B$.
2) $2$ elements of $A$ are mapped onto $1$ element of $B$, another  $2$ elements of $A$ are mapped onto another element of $B$, and the remaining element of $A$ is mapped onto the remaining element of $B$.
The mapping looks, for example, like : 
$( ||, |, || )$.
Let's start with the single element:
$5$ ways to choose an element from $A$, $3$ ways to map it to $a,b$ or $c$. Altogether: $5×3 =15$ ways.
$2$ vacant spots remain to be filled with $2$ elements of $A$ each.
$4$ elements are left in $A$, the number of ways of choosing $2$ of the remaining $4$: $ \binom{4}{2} = 6.$
To avoid double counting fix any one empty spot of $B$ (there are $2$).
There are $6$ ways to put $2$ numbers in this spot, the remaining open spot is taken care of with the remaining $2$ numbers of $A$ automatically.
Altogether there are $15×6 = 90$ ways of generating a surjective function that maps $2$ elements of $A$ onto $1$ element of $B$, another $2$ elements of $A$ onto another element of $B$, and the remaining element of $A$ onto the remaining element of $B$.
Combining: There are 60 + 90 = 150 ways.
