Different ways to generate a big number with some small numbers
This is a well-known problem called the subset sum problem. Essentially we are looking for a subset of the elements that sums up to a target value, P. The problem is NP-hard, meaning it does not admit a polynomial time solution unless P = NP.  Here is a link that explains how to solve this problem. There are multiple algorithms for the problem. The recursive one runs at in an exponential time of $O(2^n)$. This problem is mostly associated with a Dynamic Programming solution since its run-time is $O(P\cdot n)$, such a running time is called pseudo polynomial, since it is polynomial in the value of the input instead of its size (which is the log of the value).