M=1018+31 is a prime number. g=42 is a primitive root modulo M, which means that g1modM,g2modM,…,gM−1modM are all distinct integers from \[1;M). Let's define a function f(x) as the smallest positive integer p such that gp=xmodM. f is a bijection from \[1;M) to \[1;M).
Let's then define a sequence of numbers as follows:
Given n, find a_n.
The only line of input contains one integer n (0≤n≤106).
Print a_n.