Millennium interview question

Formal maths & puzzles + hackerrank.