But that's a very good exercice.
> I am first year maths student at Uni Warsaw
then Math is your major discipline. Please write down how you would express the solution in a pure mathematical form.
I guess expressing it mathematically purely is already done in the code of the original solution, because in a way program == proof. If you have some time, here's a great read on this: http://www.maa.org/sites/default/files/pdf/upload_library/22...
Bear in mind that the objective isn't to weed out people who can't solve it. There are plenty of people who are fine coders who wouldn't quickly hit the solution for any number of reasons, including nervousness. The objective is to weed out the charlatans and amateurs who managed to get past the HR resume filter, so that as little time as possible is wasted.