Formula for exercise 5