Bob says he will not retire unless he has 900,000 dollars in his 401K. He is 30 now and plans to contribute a $311 every month and his employer matches the $311. Assuming he averages a 7.1% return, when can Cruz retire?

Just plug your numbers into the formula and solve for n:

311((1 + .071/12)^(12n) - 1)/(.071/12) = 900000
(1 + .071/12)^(12n) - 1 = 900000/311 * .071/12 = 17.122
12n log 1.005917 = log 17.122
n = log17.122/(12 log1.005917)
n = 40.92