Bending Spoons interview question

logic problems, algorithm questions involving loops