Eeny Meeny Moo
Time limit1sMemory limit128 MB
For each n, find the smallest step size m so that in the elimination order starting at city 1, city 2 is eliminated last.
- Level
Medium5 of 10
- Topics
- Simulation, Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
You have surely experienced that when too many people use the Internet at the same time, the network becomes very, very slow.
To put an end to this, the University of Ulm devised a fair emergency scheme for times of peak load that cuts off Internet access for some cities in a systematic way. The country's cities are numbered from to in a purely random order: Freiburg is city , Ulm is city , Karlsruhe is city , and so on.
A number is then chosen. Internet access is first cut off in city (clearly the fairest starting point). After that, counting only the cities that are still connected and wrapping around from city back to city , every -th city is cut off in turn. For example, if and , access is cut off in the order [1, 6, 11, 16, 5, 12, 2, 9, 17, 10, 4, 15, 14, 3, 8, 13, 7].
Because it is only fair that Ulm — home of the best programmers — keeps its connection the longest, must be chosen so that city is the very last city to be cut off.
Given , write a program that finds the smallest integer for which city is cut off last.
Input
The input consists of one or more lines. Each line contains a single integer with , the number of cities in the country. The input ends with a line containing , which is not processed.
Output
For each value of , print a single line containing the smallest integer that makes city the last city to be cut off.