How many ways can we get a number by addition if each part of the addition has to be smaller or equal to a set value? For example, if we need to get 5 with the largest number we can use being 3, we can use:


*

*3 + 2

*3 + 1 + 1

*2 + 2 + 1

*2 + 1 + 1 + 1

*1 + 1 + 1 + 1 + 1


Is there any way to find out the solution with any two numbers without calculating every one of them?

It is a simple function call.  In Mathematica, for example:
IntegerPartitions[5, {1, 5}, {1, 2, 3}]

(*
{{3, 2}, {3, 1, 1}, {2, 2, 1}, {2, 1, 1, 1}, {1, 1, 1, 1, 1}}
*)
If you merely seek the number of such partitions:
Length@IntegerPartitions[5, {1, 5}, {1, 2, 3}]

(* 5 *)
[This function asks for all integer partitions of the number 5, of length 1 through 5, using only the numbers 1, 2 and 3.  Then take the "length" of this list, i.e., the number of partitions.]
Another example:
IntegerPartitions[10, {1, 10}, {1, 2, 3}]

(*
{{3, 3, 3, 1}, {3, 3, 2, 2}, {3, 3, 2, 1, 1}, {3, 3, 1, 1, 1, 1}, {3, 2, 2, 2, 1}, {3, 2, 2, 1, 1, 1}, {3, 2, 1, 1, 1, 1, 1}, {3, 1, 1, 1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {2, 2, 2, 2, 1, 1}, {2, 2, 2, 1, 1, 1, 1}, {2, 2, 1, 1, 1, 1, 1, 1}, {2, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}
*)
Length@IntegerPartitions[10, {1, 10}, {1, 2, 3}]

(* 14 *)
