#P9929. Decrypting the Encrypted Message
Decrypting the Encrypted Message
Decrypting the Encrypted Message
In this problem, you are given five integers S3, S5, S7, S1 and C which were exchanged between two parties using a special encryption method. The encryption procedure is outlined as follows:
- Setup: The sender generates large integers P, S4, S6, S7, S1 satisfying
\( P < S_{6} < S_{4}P \) and defines \( S_{5} = S_{4}P + S_{6} \). Also, it is required that \( (S_{6} \bmod P)^3 < S_{4}^3 < S_{1}^3 < (S_{1}+1)^3 < S_{7}^3 < P \). - It then computes \( S_{3} = S_{4}P + S_{5} \) and sends \( S_{3}, S_{5}, S_{7}, S_{1} \) to the receiver.
- The receiver chooses a secret \( M \) such that \( S_{1} < M < S_{7} \) (through an agreed public method). Then, two numbers w and r are chosen such that \((S_{3}-S_{5})^3 < r < w\), and the ciphertext is computed as \[ C = (S_{3}-S_{5})^3 \cdot w + M \cdot S_{5} + r(S_{3}-S_{5}). \]
- Finally, the sender (or interceptor) can recover \(M\) by computing \[ M = \frac{C \bmod P}{(2S_{5}-S_{3}) \bmod P}. \]
Your task is to recover \(M\) given only the intercepted values \(S_{3}, S_{5}, S_{7}, S_{1}\) and \(C\). Note that P is not directly given. However, observe that since \(S_{3} = S_{4}P + S_{5}\), we have \[ S_{3}-S_{5} = S_{4}P, \quad\text{so }P\text{ divides }(S_{3}-S_{5}). \] Moreover, from the constraints, there is a unique divisor \(P\) of \(S_{3}-S_{5}\) satisfying \(P > S_{7}^{3}\>.
Input: Five space‐separated integers: S3, S5, S7, S1 and C.
Output: A single integer \(M\), which is the decrypted message (satisfying \(S_{1} < M < S_{7}\)).
Note: You may assume that a unique valid \(M\) exists under the given constraints.
inputFormat
The input consists of a single line containing five space‐separated integers:
- S3
- S5
- S7
- S1
- C
It is guaranteed that these values satisfy the conditions described in the problem statement.
outputFormat
Output a single integer \(M\) which is the decrypted message.
sample
636 382 5 3 39416514310582
4