Pregunta de entrevista de Google

mathematical question. it was implementation based