First Algorithm: Straightforward calculation