Kakao Interview Question

Explain the question and solution of the previous coding test mathematically.