Exchanging coins problem

can someone explain the output of this problem.