That's no more complicated than algebra, just figure out the computer math or C3 equivalents, which is all there, and will handle this easily.
I would suggest not trying to stick it all in one equation.
Sub events make things easier and more readable.