Let’s say that you want to make $1 000 000 through regular investments. How much would you need to contribute each year if:

The interest rate was 2% and you invested for twenty years?
The interest rate was 4% and you invested for ten years?
The interest rate was 4% and you invested for twenty years?
The interest rate was 10% and you invested for twenty years?

In each case you simply have to use:

amount = payment( (1+i)^n - 1)/i

I will do the third one, you follow the same steps for the others
i= .04
n=20
amount = 1,000,000
payment = ?

payment( 1.04^20 - 1)/04 = 1000000
payment(29.77807858) = 1000000
payment = 1000000/29.77807858 = $33581.75