The formula quoted above is true can be used for any number of years as long as the rate of return and inflation rate remains the same.
In case any one factor changes after ‘n’ number of years then the real rate of return will change hence you calculate the real returns you have accumulated till that date and then calculate for the remaning period with new real rate of return.