Pregunta de entrevista de Bending Spoons

logic problems, algorithm questions involving loops