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 zones of the country in a systematic but fair manner.

Nieuw Zeeland
Live data on megawatt loads1 (MW) for each of the operational zones across New Zealand.

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

Numbering of the zones is applied cyclically, with zone 1 following immediately after zone $$n$$. For the sake of fairness, zones where the power has already been cut before are excluded when determining the zone $$m$$ positions further downstream. In this way, for example, with $$n = 17$$ zones and jump $$m = 5$$ the power is cut in the following zones 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 zone 16 the power is cut in zone 5. This is the zone $$m = 5$$ positions further downstream, taking into account the fact that the power was already cut in zone 1. To determine the zone five positions further downstream, the following zones are thus counted:

17, 2, 3, 4, 5

Still, for the sake of fairness, the problem arises that the final power cut should be in Wellington. After all, that's the zone in which the Department of Energy is located. Therefore, the arbitrary jump $$m$$ for a given number of zones $$n$$ should be carefully chosen so that zone 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)