ZOJ Problem Set - 2674
Consider sequence an defined with the following recurrence:
bn = an 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 bn 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.
Source: Andrew Stankevich's Contest #8