Solving a math problem my friend gave me