Scott Logic interview question

A math challenge/riddle and 2 coding challenges.