Let's say we have the fallowing sum of real numbers:
x + y = z
I'd like to find three other real numbers α, β and γ such that:
αx + βy = γz
αx / βy ∈ ℚ
βy / γz ∈ ℚ
So basically, how can I "scale" the terms of a sum so that each term has a common real number r that divides them "exactly" meaning that their division by r is an integer?
Your question is similar to the apportionment problem, e.g., how the US House of Representatives can assign seats in direct relation to states' populations when those populations don't have a convenient common divisor.
For the sake of having a concrete example, suppose that the two Koreas are planning to reunite, and have a 100-seat parliament apportioned to North and South by population. Let
Then $z = x + y = 77~716~785$.
If fractional seats were possible, then North Korea would get 33.418661 seats in the new all-Korean parliament, and South Korea would get 66.581339. But for practical reasons, these must be rounded to integers. Now, there are different algorithms you could use for this.
In this particular case, the choice of rounding method doesn't matter, since they all give the same result: 33 seats for the North, and 67 for the South.
With 100 total seats, the average number of constituents per representative is $\frac{77~716~785}{100} = 777~167.85$. Rounding to a whole number of seats means that the North gets representation as if it had a population of $33 \times 777~167.85 = 25~646~539.05$, and the South gets representation as if it had a population of $67 \times 777~167.85 = 52~070~245.95$. So you can get your scaling factors by comparing the “represented” population to the actual population.
$$\alpha = \frac{25~646~539.05}{25~971~909} \approx 0.987472$$ $$\beta = \frac{52~070~245.95}{51~744~876} \approx 1.006288$$ $$\gamma = \frac{77~716~785}{77~716~785} = 1$$
Multiplying the scaling factors by the variables gives the “approximated” populations.
$$\alpha x = 25~646~539.05$$ $$\beta y = 52~070~245.95$$ $$\gamma z = 77~716~785$$
Which satisfy your ratio requirements with relatively “nice” fractions.
$$\frac{\alpha x}{\beta y} = \frac{25~646~539.05}{52~070~245.95} = \frac{33}{67}$$ $$\frac{\beta y}{\gamma z} = \frac{52~070~245.95}{77~716~785} = \frac{67}{100}$$
The pseudo-common divisor $r$ is the average population per representative, $\frac{z}{n}$, where $n$ is the number of seats.
One thing I've glossed over is how to pick $n$. I chose $n = 100$ because it's a convenient “round” number, but this is completely arbitrary. You can make a different choice. Like a highly-composite number, to make convenient fractions. Or choose an $n$ that makes the scaling factors $\alpha$ and $\beta$ as close to 1 as possible. Or if you're actually apportioning a legislature, you might want to have $n$ be an odd number, so as to avoid tie votes.
To summarize:
Suppose that you have a list of $x_i$ values, and $z = \sum x_i$. You want to find scaling factors $\alpha_i$ such that $\sum \alpha_i x_i = z$ and each $\alpha_i x_i$ is an integer multiple of $r \in \mathbb{R}$. Then: