{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003ch1\u003e\u003cfont color\u003d\"#000\"\u003eProblem A:\u003c/font\u003e \u003c/h1\u003e\n\n\u003cp\u003e\nLet’s play a stone removing game.\n\u003c/p\u003e\n\n\u003cp\u003e\nInitially, \u003ci\u003en\u003c/i\u003e stones are arranged on a circle and numbered 1, ... , \u003ci\u003en\u003c/i\u003e clockwise (Figure 1). You are also given two numbers \u003ci\u003ek\u003c/i\u003e and \u003ci\u003em\u003c/i\u003e. From this state, remove stones one by one following the rules explained below, until only one remains. In step 1, remove stone \u003ci\u003em\u003c/i\u003e. In step 2, locate the \u003ci\u003ek\u003c/i\u003e-th next stone clockwise from \u003ci\u003em\u003c/i\u003e and remove it. In subsequent steps, start from the slot of the stone removed in the last step, make \u003ci\u003ek\u003c/i\u003e hops clockwise on the remaining stones and remove the one you reach. In other words, skip (\u003ci\u003ek\u003c/i\u003e - 1) remaining stones clockwise and remove the next one. Repeat this until only one stone is left and answer its number.\n\u003c/p\u003e\n\u003cp\u003e\nFor example, the answer for the case \u003ci\u003en\u003c/i\u003e \u003d 8, \u003ci\u003ek\u003c/i\u003e \u003d 5, \u003ci\u003em\u003c/i\u003e \u003d 3 is 1, as shown in Figure 1.\n\u003c/p\u003e\n\n\u003ccenter\u003e\n\u003cimg src\u003d\"CDN_BASE_URL/e2738dcf30e841cf829ff6842358dbe9?v\u003d1714948403\"\u003e\n\u003cp\u003e\nFigure 1: An example game\n\u003c/p\u003e\n\u003c/center\u003e\n\n\u003cp\u003e\n\u003cb\u003eInitial state\u003c/b\u003e: Eight stones are arranged on a circle.\n\u003c/p\u003e\n\u003cp\u003e\n\u003cb\u003eStep 1\u003c/b\u003e: Stone 3 is removed since \u003ci\u003em\u003c/i\u003e \u003d 3.\n\u003c/p\u003e\n\u003cp\u003e\n\u003cb\u003eStep 2\u003c/b\u003e: You start from the slot that was occupied by stone 3. You skip four stones 4, 5, 6 and 7 (since \u003ci\u003ek\u003c/i\u003e \u003d 5), and remove the next one, which is 8.\n\u003c/p\u003e\n\n\u003cp\u003e\n\u003cb\u003eStep 3\u003c/b\u003e: You skip stones 1, 2, 4 and 5, and thus remove 6. Note that you only count stones that are still on the circle and ignore those already removed. Stone 3 is ignored in this case.\n\u003c/p\u003e\n\n\u003cp\u003e\n\u003cb\u003eSteps 4-7\u003c/b\u003e: You continue until only one stone is left. Notice that in later steps when only a few stones remain, the same stone may be skipped multiple times. For example, stones 1 and 4 are skipped twice in step 7.\n\u003c/p\u003e\n\n\u003cp\u003e\n\u003cb\u003eFinal State\u003c/b\u003e: Finally, only one stone, 1, is on the circle. This is the final state, so the answer is 1.\n\u003c/p\u003e\n\n\n\n\u003ch2\u003eInput\u003c/h2\u003e\n\n\u003cp\u003e\nThe input consists of multiple datasets each of which is formatted as follows.\n\u003c/p\u003e\n\n\u003cpre\u003e\u003ci\u003en k m\u003c/i\u003e\n\u003c/pre\u003e\n\n\u003cp\u003e\nThe last dataset is followed by a line containing three zeros. Numbers in a line are separated by a single space. A dataset satisfies the following conditions.\n\u003c/p\u003e\n\u003ccenter\u003e\n\u003cp\u003e\n 2 ≤ \u003ci\u003en\u003c/i\u003e ≤ 10000, 1 ≤ \u003ci\u003ek\u003c/i\u003e ≤ 10000, 1 ≤ \u003ci\u003em\u003c/i\u003e ≤ \u003ci\u003en\u003c/i\u003e\n\u003c/p\u003e\n\u003c/center\u003e\n\n\u003cp\u003e\nThe number of datasets is less than 100.\n\u003c/p\u003e\n\n\u003ch2\u003eOutput\u003c/h2\u003e\n\n\u003cp\u003e\nFor each dataset, output a line containing the stone number left in the final state. No extra characters such as spaces should appear in the output.\n\u003c/p\u003e\n\n\u003ch2\u003eSample Input\u003c/h2\u003e\n\u003cpre\u003e8 5 3\n100 9999 98\n10000 10000 10000\n0 0 0\n\u003c/pre\u003e\n\n\u003ch2\u003eOutput for the Sample Input\u003c/h2\u003e\n\u003cpre\u003e1\n93\n2019\n\u003c/pre\u003e\n\n\n\n\n"}}]}