During the winter of 2011, New Zealand was coping with a lack of rain. As a consequence, the reservoirs of hydroelectric plants were hardly filled, which led to the country being hit by a severe energy crisis. The Department of Energy had to develop an emergency plan in which the power would be cut in certain areas of the country in a systematic but fair manner.

Nieuw Zeeland

In this emergency plan, the country was divided into $$n$$ areas, with the area around Auckland assigned the number 1 and the area around Wellington assigned the number 13. First, the power would be cut in area 1 (this seemed to be the fairest starting point) and then successively in each area $$m$$ positions further downstream the list of areas. In this, $$m$$ is an arbitrary number (with $$m > 0$$) called the jump.

Numbering of the areas is applied cyclically, with area 1 following immediately after area $$n$$. For the sake of fairness, areas where the power has already been cut before are excluded when determining the area $$m$$ positions further downstream. In this way, for example, with $$n = 17$$ areas and jump $$m = 5$$ the power is cut in the following areas according to the emergency plan:

1, 6, 11, 16, 5, 12, 2, 9, 17, 10, 4, 15, 14, 3, 8, 13, 7

Pay attention to the fact that, for example, after area 16 the power is cut in area 5. This is the area $$m = 5$$ positions further downstream, taking into account the fact that the power was already cut in area 1. To determine the area five positions further downstream, the following areas are thus counted:

17, 2, 3, 4, 5

Still, for the sake of fairness, the problem arises that the power in Wellington should be cut last. After all, that's the area in which the Department of Energy is located. Therefore, the arbitrary jump $$m$$ for a given number of areas $$n$$ should be carefully chosen so that region 13 is selected last. A value of $$m$$ that meets this requirement is called a valid jump.

Assignment

Example

>>> emergency_plan(17, 5)
[1, 6, 11, 16, 5, 12, 2, 9, 17, 10, 4, 15, 14, 3, 8, 13, 7]
>>> emergency_plan(16, 11)
[1, 12, 8, 5, 3, 2, 4, 7, 11, 16, 14, 15, 10, 6, 9, 13]

>>>
valid_jump(17) 7 >>> valid_jump(14)