Given an array A of N elements. We need to find the number of subsets (with repetition of numbers allowed) such that the number of elements in the subset is P and the sum of those P elements is divisible by M.
N can be upto 10^5
P can be upto 10^5
M can be upto 10
Elements in the array can be upto 10^9
What I thought: I thought of generating subset sum using dynamic programming starting from sum=M till sum=P*max(A) and then find all the subset sums which are divisible by M but it will surely be too unefficient. Any idea how can I solve this problem?
Subset sum (with repetition allowed) algorithm can be seen here: https://tutorialspoint.dev/algorithm/dynamic-programming-algorithms/ways-sum-n-using-array-elements-repetition-allowed
Even small hints about the approach would be appreciated