Oh, and if anyone would like a version of the formulas that work when you already have an amount invested, I'll put them here too:
C = Your current amount of savings invested or available to invest
X = (T - C * (1 + R)^N) * R / ((1 + R)^N - 1)
N = log(base 1 + R) ((T * R + X) / (C * R + X)) = ln((T * R + X) / (C * R + X)) / ln(1 + R)