SP2161 JPIX - Pixel Shuffle

Description

![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2161/35273a4a0cb45de5f69e7e442d9ddb8a59707031.png) Shuffling the pixels in a bitmap image sometimes yields random looking images. However, by repeating the shuffling enough times, one finally recovers the original images. This should be no surprise, since "shuffling" means applying a one-to-one mapping (or permutation) over the cells of the image, which come in finite number. Your program should read a number n , and a series of elementary transformations that define a "shuffling" ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2161/598fb30f65716b2690333cbde24b47b998008bf8.png) of n \* n images. Then, your program should compute the minimal number m (m > 0) , such that m applications of ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2161/598fb30f65716b2690333cbde24b47b998008bf8.png) always yield the original n \* n image. For instance if ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2161/598fb30f65716b2690333cbde24b47b998008bf8.png) is counter-clockwise 90 $ ^{o} $ rotation then m = 4. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2161/81c6ff4e922996a836a6330d195cd68c52a6c23d.png)

Input Format

Test cases are given one after another, and a single 0 denotes the end of the input. For each test case: Input is made of two lines, the first line is number n (2

Output Format

For each test case: Your program should output a single line whose contents is the minimal number m (m > 0) such that ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2161/598fb30f65716b2690333cbde24b47b998008bf8.png) is the identity. You may assume that, for all test input, you have m < 2 $ ^{31} $ .