How to find a list of summands and factors adding up to a total?

645 Views Asked by At

I am neither a mathematician nor do I have an idea on how to write down my problem in accurate mathematic formulas. Please feel free to edit my question into shape and remove this paragraph. Also I am unsure about that tags that apply to this question - fits, but maybe there are others?

Given a set of natural numbers: [125, 70, 55] and a total of 250 (All of these numbers may vary).

Now I need to find the integral factors to the numbers that add up to the total like this:

125*a + 70*b + 55*c = 375

Is there a mathematical solution to this problem or do I have to find out the brute force way?

For this example there is more than one valid solution:

  • a = 3, b = 0, c = 0
  • a = 2, b = 1, c = 1
  • a = 1, b = 2, c = 2
  • a = 0, b = 3, c = 3
  • a = 0, b = 1, c = 5
  • maybe others...

My goal is it to find all possible solutions - or at least more than one of them.

I already tried some brute force algorithms, but none of them is fast enough to find a solution to this problem for lager numbers.