Scott Logic Interview Question

A math challenge/riddle and 2 coding challenges.