
ZOJ Problem Set  2674
Consider sequence a_{n} defined with the following recurrence:
a_{1}= p, b_{n} = a_{n} mod m!, where m! denotes m factorial, that is m! = 1 · 2 · ... · m.It may seem strange, but for all p and all m the sequence b_{n} has limit as n . Your task is to find it. Given p and m, find
InputThere are several test cases in the input. Each case contains p and m (2 <= p, m <= 12, p is prime). There is am empty line between each case.OutputOutput the limit requested. There should be am empty line between each case.Example
Source: Andrew Stankevich's Contest #8 