1

Suppose i have 3 coins: A, B, C. Each one of them have different value: a, b, c. And if want to exchange coins A for coins B, i need to be able to give exactly a units of currency A and get exactly b units of currency B in return. The problem is to find how many different triples of coins i can have? For example, if i got 1 coins of A, 0 coins of B, 3 coins of C, and its currencies is a=1 b=1 c=1, i can have 10 different triples of values:

  • 0 0 3
  • 0 3 0
  • 3 0 0
  • 1 0 2
  • 1 2 0
  • 2 1 0
  • 0 1 2
  • 0 2 1
  • 2 0 1
  • 1 1 1

Is there any mathematical formula that allows me to do this calculation without looping through all possible triples? (1 ≤ A, B, C ≤ 10^9), (0 ≤ a, b, c ≤ 10^9)

dezzerlol
  • 11
  • 1

1 Answers1

0
  1. Introduce integer variables $x,y,z$. Let $x$ count the number of times that you've exchanged a units of currency A for b units of currency B, $y$ count the number of times that you've exchanged a units of currency A for c units of currency C, and $z$ count the number of times that you've exchanged b units of currency B for c units of currency C.

  2. Write down linear inequalities on $x,y,z$ that determine which values lead to an admissible triple. (This is your programming contest / exercise problem, so you get to do this part.)

  3. Implement an algorithm to count the number of solutions to this integer linear program, or equivalently, count the number of integer lattice points in this convex polytope. See, e.g., Finding all solutions to an integer linear programming (ILP) problem, https://math.stackexchange.com/questions/3001715/find-the-number-of-non-negative-integer-solutions-to-linear-systems, Counting the number of satisfied models - given mathematical constraints.

  4. Submit to your programming contest and win the contest. Make sure to credit all sources that you used in doing so.

D.W.
  • 159,275
  • 20
  • 227
  • 470