This page is still under construction.

Parts of this page are still being built. What you see may change.

Eeny Meeny Moo

Time limit1sMemory limit128 MB

Summary
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 11 to nn in a purely random order: Freiburg is city 11, Ulm is city 22, Karlsruhe is city 33, and so on.

A number mm is then chosen. Internet access is first cut off in city 11 (clearly the fairest starting point). After that, counting only the cities that are still connected and wrapping around from city nn back to city 11, every mm-th city is cut off in turn. For example, if n=17n = 17 and m=5m = 5, 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, mm must be chosen so that city 22 is the very last city to be cut off.

Given nn, write a program that finds the smallest integer mm for which city 22 is cut off last.

Input

The input consists of one or more lines. Each line contains a single integer nn with 3≤n<1503 \le n < 150, the number of cities in the country. The input ends with a line containing 00, which is not processed.

Output

For each value of nn, print a single line containing the smallest integer mm that makes city 22 the last city to be cut off.

Examples2

  1. Example 1

    Input
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    0
    
    Expected output
    2
    5
    2
    4
    3
    11
    2
    3
    8
    16
    
  2. Example 2

    Input
    3
    0
    
    Expected output
    2