How is compound interest calculated using a formula?