Very simple#4898

Very simple

1 sekunt
128 megabaýt
Örän ýeňil

Alice and Bob want to secretly transmit messages to each other. For this, they have developed a random number generator (RNG), which is initialized with three integers: a_0, a_1, and . The first elements of the RNG are a_0 and a_1, and the following elements are constructed as follows:

a_{i+2} = (a_{i+1}^2 + a_i^2) \bmod n, \quad i = 0, 1, \ldots

Alice and Bob will use the RNG in the data transfer scheme, as shown in the figure below.

prb4898

To create the RNG, they want to write a procedure that calculates the value of a_k for a given . Help them!

\InputFileOne line contains four integers , a_0, a_1, and (0 \leq a_0, a_1 < n \leq 200, 0 \leq k \leq 10^9).

\OutputFilePrint the value of a_k.

Mysallar

1-nji mysal

Loading
Loading

2-nji mysal

Loading
Loading

3-nji mysal

Loading
Loading