luogu#P9929. [NFLSPC #6] 挑战大数因子分解

[NFLSPC #6] 挑战大数因子分解

Background

NFLSPC #6 is coming soon. SolarPea, who cannot attend on-site, wants to send the std of his problem to PolarSea, who can attend.

To prevent contestants from eavesdropping on their communication to obtain the std, they plan to use a public-key encryption algorithm to ensure secure communication.

So SolarPea used an algorithm he saw on Zhihu that claims to have the “highest encryption/decryption speed and security”. Its security “depends on the hard problem of big integer factorization”:

You are a contestant with a factorization oracle, and you have already obtained the public key and the plaintext. Please use your factorization oracle to crack the std.

Problem Description

Since the image may not be clear, we restate the encryption algorithm here:

  • Suppose SolarPea wants to send a message MM' to PolarSea. They will perform the following steps.
  • PolarSea first generates five big integers P,S4,S6,S7,S1P, S_4, S_6, S_7, S_1, such that P<S6<S4PP < S_6 < S_4P and S5=S4P+S6S_5 = S_4P + S_6 and $(S_6\bmod P) ^ 3 < S_4 ^ 3 < S_1 ^ 3 < (S_1 + 1) ^ 3 < S_7 ^ 3 < P$, and computes S3=S4P+S5S_3 = S_4P + S_5.
  • Then PolarSea sends S3,S5,S7,S1S_3, S_5, S_7, S_1 to SolarPea.
  • SolarPea receives these four numbers from PolarSea. First, he needs to construct an MM such that S1<M<S7S_1 < M < S_7, and agree with PolarSea on a method to derive MM' from MM (for example, if MM' is a relatively small positive integer, one can set M=M+S1M = M' + S_1). This method is not secret, so obtaining MM is equivalent to obtaining MM'. Therefore, you can ignore MM' and only focus on MM.
  • SolarPea generates two numbers w,rw, r satisfying (S3S5)3<r<w(S_3 - S_5) ^ 3 < r < w, and computes C=(S3S5)3w+MS5+r(S3S5)C = (S_3 - S_5) ^ 3w + MS_5 + r(S_3 - S_5), then sends CC to PolarSea.
  • PolarSea only needs to compute $\frac{C \operatorname{\bmod} P}{(2S_5 - S_3) \operatorname{\bmod} P}$ to obtain MM.

Now you have intercepted all communications between PolarSea and SolarPea (i.e., S3,S5,S7,S1,CS_3, S_5, S_7, S_1, C). Please use the known information to recover MM.

Input Format

The first line contains four integers S3,S5,S7,S1S_3, S_5, S_7, S_1, which represent the public key.

The second line contains an integer CC, which represents the ciphertext.

Output Format

Output one line containing an integer MM satisfying S1<M<S7S_1 < M < S_7, which is the recovered plaintext. It can be proven that under the given constraints, MM is unique.

7001 4001 7 5
1155511307999246176590006

6

11083610 7305110 52 32
4578384821991465584924042474394616310820101790

39

Hint

Explanation for Sample 1

The generated values are P=1000P=1000, S4=3S_4=3, S6=1001S_6=1001, S7=7S_7=7, S1=5S_1=5. The computed values are S5=4001S_5=4001, S3=7001S_3=7001.

The plaintext is M=6M=6. During encryption, the chosen values are w=42796713439376w=42796713439376, r=15045364725522r=15045364725522, and the encryption result is C=1155511307999246176590006C=1155511307999246176590006.

Of course, this encryption is very weak this time, because 66 is the only integer between 55 and 77.

Constraints and Notes

For all data, P<10500P < 10 ^ {500}, C<P10C < P^{10}.

  • Subtask 1 (2020 points): P<106P < 10 ^ 6.
  • Subtask 2 (2020 points): P<1018P < 10 ^ {18}.
  • Subtask 3 (2020 points): PP is prime.
  • Subtask 4 (2020 points): all numbers are randomly generated.
  • Subtask 5 (2020 points): no special restrictions.

Source: NFLSPC #6 E by asmend

Translated by ChatGPT 5